WCF Rest Post Service issue
Hi all,
I am new to WCF Rest , I had created a WCF service with ServiceContract as follows
And my Person Class is defined as
I used Google chrome’s Simple rest client to make rest call
And I pass following xml as data
I have enabled debugging in WCF rest server. The rest call successfully entering but only one value in the requesting object is get initialised that is person object in data contract has only [MiddleName] all other values are not initialised and is set to null
Then I changed the person class as follows
And current request xml data is as follows
Now all the person object is get initialised with data’s in the xml. I am confused what had gone wrong with me...
Please reply, thanks in advance
Syam.S
Hi all,
I am new to WCF Rest , I had created a WCF service with ServiceContract as follows
Code:
[OperationContract] [WebInvoke(Method = "POST", UriTemplate = "/SampleService", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] string SampleService(Person personObj); Datacontract is like as follows public string SampleService(Person personObj) { return "Sucess"; }
Code:
using System.Runtime.Serialization; namespace CMPCO.BusinessLayer.BusinessObject { [DataContract(Namespace = "http://www.test.com")] public class Person { [DataMember ( Name="MiddleName")] public string MiddleName { get; set; } [DataMember(Name = "FirstName")] public string FirstName{ get ; set;} [DataMember(Name = "LastName")] public string LastName{ get; set;} [DataMember(Name = "Age")] public string Age { get; set; } } }
And I pass following xml as data
Code:
<?xml version="1.0" encoding="utf-8" ?> <Person xmlns="http://www.test.com"> <MiddleName>mName</MiddleName> <FirstName>fName</FirstName> <LastName>lname</LastName> <Age>23</Age> </Person>
Then I changed the person class as follows
Code:
namespace CMPCO.BusinessLayer.BusinessObject { [DataContract(Namespace = "http://www.test.com")] public class Person { [DataMember(Name = "item1")] public string MiddleName { get; set; } [DataMember(Name = "item2")] public string FirstName{ get ; set;} [DataMember(Name = "item3")] public string LastName{ get; set;} [DataMember(Name = "item4")] public string Age { get; set; } } }
Code:
<?xml version="1.0" encoding="utf-8" ?> <Person xmlns="http://www.test.com"> <item1>mName</item1> <item2>fName</item2> <item3>lname</item3> <item4>26</item4> </Person>
Please reply, thanks in advance
Syam.S
Comment