C#SOAP客户端无法反序列化响应(“XML文档中存在错误”)

时间:2012-12-14 12:35:14

标签: c# xml web-services serialization soap

我在项目中添加了对Web Service的引用。我正在使用生成的代码来调用Web Service的方法。其中一个方法返回以下结构:

    <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>

负责反序列化的生成代码会引发以下异常:

  

类型'System.InvalidOperationException'的未处理异常   发生在System.Xml.dll中附加信息:出错   在XML文档(168361,13)中。

我在代码示例中标记了异常中提到的行。我想这与它是最后一个item对象的结束标记这一事实有关。我不知道为什么会失败。 XML格式良好,似乎不包含任何不受支持的字符。

2 个答案:

答案 0 :(得分:1)

只是一个猜测,但检查您的数据,可能是其中一个字段有&#39;&lt;&#39;或者&#39;&gt;&#39;抛弃xml文档的格式。

答案 1 :(得分:0)

我看到你有两个关闭的项目标签。当然,您可能会排除某些XML文件。但是,连续两个结束标记肯定会导致错误。

相关问题