WCF: Technique of debugging inconsistency in Wsdl and Response messages.

I have consumed severalWCF services whereWSDLs do not conform the Response messagess (See below. I’ve bolded the sample text related to one issue.).We canfix the issues by changing proxy code. It’s not a big issue but now we must manually change proxy every time we have updated the proxy of this service.

Here the checklist howwe debug this case:

[I’ve created the proxy for the web-service using any method in Visual Studio 2008 like “Add Service Reference” command.]

1. We have found that the client code cannot get all data from the service. Some data are lost.

2. Using SoapUI make sure the Response returned all data. This is a sign of this inconsistency!

3. Using debugger we havefound that data are lost exactly in
response = client.Method(request)
line in the client code.

What does it mean? The data is successfully returned in the Response message. But the client proxy code cannot process it. When the proxy code is deserializing the response message some data are lost. SoapUI does not process returned data, it just shows them as raw text. My proxy code is trying to deserialize this text, convert text to objects in memory. [The deserializer is the code in the Microsoft libraries in the System.Runtime.Serialization namespace. There are two of them in WCF: XmlSerializer and DataContractSerializer.] Some of returned data disappeared during the Deserializing process. These cases are described in article “WCF: values disappeared in response: derived classes and serialization/deserialization order error” [http://geekswithblogs.net/LeonidGaneline/archive/2008/05/01/wcf-values-disappeared-in-response-derived-classes-and-serializationdeseriazlization-order.aspx]

4. We have to openthe proxy source code (maybe in Reference.cs file) and fix code (see below). That makes it inconsistent with Wsdl file and next time when you update this Web or Service reference you have to fix code again. But your client is fixed now!

5. Document this fix! And do not make it in proxy code. J

You are lucky if you have gotinconsistency in Response messages. The worst situation if inconsistency is in Request messages. There are only two options: the service does not care about these inconsistencies and you are lucky again, or service rejects your request with a fault message. Moreover I make sure this message does not give you any clue what is going on. Just try to get the “correct” request from any source.


[WSDL ]

<xsd:complexType name=ArrayOf_xsd_string>

<xsd:sequence>

<xsd:element minOccurs=0 maxOccurs=unbounded name=item type=xsd:string />

</xsd:sequence>

</xsd:complexType>

<xsd:complexType name=PromoDetails>

<xsd:sequence>

<xsd:element name=assetTypes nillable=true type=impl:ArrayOf_xsd_string />

</xsd:sequence>


[Response message]

<assetTypes>

<assetTypes>Album</ assetTypes >

</assetTypes>


[Response message How it should be with regard to WSDL]

<assetTypes>

<item>Album</ item >

</assetTypes>


[Auto generated Proxy code]

private string[] assetTypesField;

[System.Xml.Serialization.XmlArrayAttribute(IsNullable=true, Order=1)]

[System.Xml.Serialization.XmlArrayItemAttribute(“item”, IsNullable = false)]

public string[] assetTypes {

get {

return this.assetTypesField;

}

set {

this.assetTypesField = value;

this.RaisePropertyChanged(“assetTypes”);

}

}


[Fixed Proxy code]

private string[] assetTypesField;

[System.Xml.Serialization.XmlArrayAttribute(IsNullable=true, Order=1)]

[System.Xml.Serialization.XmlArrayItemAttribute(“assetTypes “, IsNullable = false)]

public string[] assetTypes {

get {

return this.assetTypesField;

}

set {

this.assetTypesField = value;

this.RaisePropertyChanged(“assetTypes”);

}

}