Calling a webservice in C#, when the response is de-serialized, the values are all shown as null.

I have captured data using Fiddler and the I can see the XML data.

The request is as follows:

<s:Envelope xmlns:s=""
        <VsDebuggerCausalityData xmlns="">
        <o:Security s:mustUnderstand="1"
            <u:Timestamp u:Id="_0">
            <o:UsernameToken u:Id="uuid-7e43c8af-1f07-42dd-89b5-6bc295e5d0f6-1">
                <o:Password Type="">password</o:Password>
        <CancelService xmlns="">
            <request xmlns:a="" xmlns:i="">
                <a:Required_Date i:nil="true"/>

and the response is:

<?xml version="1.0"?>
<soapenv:Envelope xmlns:soapenv=""
        <CancelServiceResponse xmlns="">
                <Status_Description>Service_ID=R-PMSR-19001188 not found.</Status_Description>

enter image description here

I am running out of ideas...


ServiceReference3.B2BServiceClient b2BServiceClient = new ServiceReference3.B2BServiceClient();
            var elements = b2BServiceClient.Endpoint.Binding.CreateBindingElements();
            elements.Find<SecurityBindingElement>().EnableUnsecuredResponse = true;
            b2BServiceClient.Endpoint.Binding = new CustomBinding(elements);

            ServiceReference3.CancelRequest cancelRequest = new ServiceReference3.CancelRequest
                Service_ID = "R-PMSR-19001188",
                Provider_Ref = "Oliver_Disconnect_BB"

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls | SecurityProtocolType.Ssl3;

            b2BServiceClient.ClientCredentials.UserName.UserName = "username";
            b2BServiceClient.ClientCredentials.UserName.Password = "password";

            ServiceReference3.Response response = b2BServiceClient.CancelService(cancelRequest);

EDIT 2: Further to this, I have seen the values in ExtensionData that is also being passed back in the response.

2 Answers

user2260040 On Best Solutions

Finally, figured out what the issue was. The Reference.cs generated from wsdl, the datacontract for the Response class had the wrong namespace.

Changing it to:

[System.Runtime.Serialization.DataContractAttribute(Name="Response", Namespace="")]


[System.Runtime.Serialization.DataContractAttribute(Name="Response", Namespace="")]

solved the issue for now.

Ackelry Xu On

Your message has only three property Status_Code , Status_Description, Order_ID and your response object has more property.

WCF deserialize message by order, so if it doesn't find the property in your message at the place where you define the property, this may cause null value, even the property is in the response message.

So please include all the property in order in your response message.

Or you could try to specify the deserializing order of model by using Order property of DataMember.

public  class Parent
 // IsRequired is used to test whether has received the property

 // if not, it will show error. Order could change the order of the property in message 
    [DataMember(IsRequired = true,Order =2)]
    public int Field3 { get; set; }
   [DataMember(IsRequired = true,Order =1)]
   public int Field1 { get; set; }


Try to specify the order of Status_Code to first , Status_Description to second and so on to see whether this solve your problem.