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

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

 

I was working with several web-services as a client and had several issues the same kind. WSDL of this services does not conform the Response messages (See below. I’ve bolded the text related to the issue.). I fixed this issue by changing proxy code. It is not a big issue but now we have to manually change proxy every time we have updated the proxy of this service.

 

Here the checklist how debugging this case:

[The proxy for the web-service could be created with any method in Visual Studio 2008 as “Add Service Reference”.]

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 returns all data. This is the sign of this inconsistency!

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

What does it mean? The data are successfully returned in the Response message. But the client proxy 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 as raw text. The proxy code is trying to deserialize this text, converting 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 proxy inconsistent with Wsdl file and next time when you update this Web or Service reference you have to fix proxy code again. But the client deserializes the Response messages properly now!

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

You lucky if you have got 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 lucky again, or service reject your request with fault message. Moreover I make sure this message does not give you a clue what is going on.  Try to get the “correct” request from any source and follow the same debugging technique with it.

 

 


[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");

            }

        }

 


Print | posted on Tuesday, May 13, 2008 4:36 PM

Feedback

No comments posted yet.
Post A Comment
Title:
Name:
Email:
Comment:
Verification: