WCF: Technique to debug inconsistency in Wsdl and Response messages.
I consume WCF service, create a client to use it. WSDL of this service does not conform the Response messages (See below. I’ve bolded the text related to the issue.). Now I fixed this issue by changing proxy code. It’s not a big issue but now we must manually change proxy each time we have updated the proxy of this service.
Here the checklist how I 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. I’ve found my client code cannot get all data from the service. Some data are lost.
2. Using SoapUI make sure the Response returns all data. This is a sign of this inconsistency!
3. Using debugger I’ve found that data are lost exactly in
response = client.Method(request)
line in my client code.
What does it mean? The data are happily returned in the Response message. But my code could not process them. When the proxy code is deserializing the response message some data are lost. SoapUI does not process returned data, it just shows them like 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 magically disappeared in the Deserializing process. Description of these cases is 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. Go to the proxy source code (maybe in Refeference.cs file) and fix code (see below). This make it inconsistent with Wsdl file and next time when you update this Web or Service reference you must fix code again. But your client is fixed now!
5. Document this fix! And do not make it in proxy code. J
You happy if you have inconsistency 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 again happy, or service reject your request with fault message. And I make sure this message does not give you a clue what’s 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");
}
}
…
