I added a reference to a Web Service in my project. I’m using the generated code to call the methods of the Web Service. One of the methods returns the following structure:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:typens="urn:AllegroWebApi" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<typens:doGetCatsDataResponse>
<cats-list xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="typens:CatInfoType[24051]">
<item xsi:type="typens:CatInfoType">
<cat-id xsi:type="xsd:int">26013</cat-id>
<cat-name xsi:type="xsd:string">Antyki i Sztuka</cat-name>
<cat-parent xsi:type="xsd:int">0</cat-parent>
<cat-position xsi:type="xsd:int">0</cat-position>
<cat-is-product-catalogue-enabled xsi:type="xsd:int">0</cat-is-product-catalogue-enabled>
</item>
....
</item>
<item xsi:type="typens:CatInfoType">
<cat-id xsi:type="xsd:int">124895</cat-id>
<cat-name xsi:type="xsd:string">Pozostałe</cat-name>
<cat-parent xsi:type="xsd:int">124883</cat-parent>
<cat-position xsi:type="xsd:int">5</cat-position>
<cat-is-product-catalogue-enabled xsi:type="xsd:int">0</cat-is-product-catalogue-enabled>
</item>
<item xsi:type="typens:CatInfoType">
<cat-id xsi:type="xsd:int">124894</cat-id>
<cat-name xsi:type="xsd:string">Teleskopy</cat-name>
<cat-parent xsi:type="xsd:int">124883</cat-parent>
<cat-position xsi:type="xsd:int">6</cat-position>
<cat-is-product-catalogue-enabled xsi:type="xsd:int">0</cat-is-product-catalogue-enabled>
</item> // Line 168361 <--------------- HERE
</cats-list>
<ver-key xsi:type="xsd:long">91632766</ver-key>
<ver-str xsi:type="xsd:string">1.1.47</ver-str>
</typens:doGetCatsDataResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
The generated code that is responsible for deserializing it throws the following exception:
An unhandled exception of type ‘System.InvalidOperationException’
occurred in System.Xml.dll Additional information: There is an error
in XML document (168361, 13).
I marked the line that is mentioned in the exception in the code sample. I guess it has something to do with the fact that it is the closing tag of the last item object. I have no idea why it is failing. The XML is well formated and does not seem to include any unsupported characters.
Just a guess, but check your data, could be one of the fields has a ‘<‘ or ‘>’ throwing off the formatting of the xml document.