Note that there are some explanatory texts on larger screens.

plurals
  1. POWSDL generated code not deserializing long in XML properly
    text
    copied!<p>I have been given a WSDL by one of our suppliers that contains the following:</p> <pre><code>&lt;xsd:element name="RegistrationResponse"&gt; &lt;xsd:complexType&gt; &lt;xsd:sequence&gt; &lt;xsd:element name="DateTimeStamp" type="xsd:dateTime" nillable="true"/&gt; &lt;xsd:element name="EchoData" type="xsd:string" nillable="true"/&gt; &lt;xsd:element name="TransactionTrace" type="xsd:long" nillable="true"/&gt; &lt;xsd:element name="ResponseCode" type="xsd:int" nillable="true"/&gt; &lt;xsd:element name="ResponseMessage" type="xsd:string" nillable="true"/&gt; &lt;xsd:element name="ClientAccNumber" type="xsd:long" nillable="true"/&gt; &lt;xsd:element name="BranchCode" type="xsd:int" nillable="true"/&gt; &lt;xsd:element name="HIN" type="xsd:long" nillable="true"/&gt; &lt;xsd:element name="EasyPayRef" type="xsd:long" nillable="true"/&gt; &lt;/xsd:sequence&gt; &lt;/xsd:complexType&gt; &lt;/xsd:element&gt; </code></pre> <p>However sometimes the response I get back from them will not contain all the fields. For example in this instance:</p> <pre><code> &lt;soapenv:Body&gt; &lt;tpw:RegistrationResponse&gt; &lt;DateTimeStamp&gt; 2012-04-02T19:10:41.4430564Z &lt;/DateTimeStamp&gt; &lt;EchoData/&gt; &lt;TransactionTrace&gt; 5418721751027669946 &lt;/TransactionTrace&gt; &lt;ResponseCode&gt; 25 &lt;/ResponseCode&gt; &lt;ResponseMessage&gt; Invalid Mobile Account Type &lt;/ResponseMessage&gt; &lt;ClientAccNumber/&gt; &lt;BranchCode/&gt; &lt;HIN&gt; 0 &lt;/HIN&gt; &lt;EasyPayRef/&gt; &lt;/tpw:RegistrationResponse&gt; &lt;/soapenv:Body&gt; </code></pre> <p>Now the code generated by the code in Visual Studio when adding a service reference does not like the fact that the ClientAccNumber is blank. The generated code looks as follows:</p> <pre><code>[System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://tpwebservice.x.com", Order=5)] [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=true)] public System.Nullable&lt;long&gt; ClientAccNumber; </code></pre> <p>I get an 'Input was not in the correct format' exception when it tries to deserialize the response received from the server. What I'm thinking is that it sees a blank string and tries to parse a long out of it, which obviously fails. I tried to add minOccurs="0" to the wsdl which didn't help.</p> <p>How do I fix the wsdl, or the generated code, to solve this problem? Or is there something else I am missing?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload