I have a WCF service, for example:
public class Service1 : IService1 { public string GetData(Person person) { if (person != null) { return "OK"; } return "Not OK!"; }
Here is my Person class:
[DataContract] public class Person { [DataMember] public int Age { get; set; } [DataMember] public string Name { get; set; } }
And I call like this:
BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None); IChannelFactory<IRequestChannel> factory = binding.BuildChannelFactory<IRequestChannel>(new BindingParameterCollection()); factory.Open(); EndpointAddress address = new EndpointAddress(url); IRequestChannel irc = factory.CreateChannel(address); using (irc as IDisposable) { irc.Open(); string soapMessage = "<GetData><person><Age>24</Age><Name>John</Name></person></GetData>"; XmlReader reader = XmlReader.Create(new StringReader(soapMessage)); Message m = Message.CreateMessage(MessageVersion.Soap11,"http://tempuri.org/IService1/GetData", reader); Message ret = irc.Request(m); reader.Close(); return ret.ToString(); }
When I try to send a complex type of type Person as a parameter to the GetData method, the person object comes up null. But I have no problem when I send as a parameter a known type of type integer, string, etc.
How do I pass a complex type as a parameter to a service method?
source share