问题从WSDL生成正确的代理对象

时间:2010-03-17 13:05:41

标签: c# .net serialization wsdl

我遇到了.NET中的WSDL生成器问题。它缺少一种特定方法中的复杂类型。

来自网络服务的回复

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://www.x.com/2.6.0">
<SOAP-ENV:Body>
 <ns1:Export.GetData xmlns:ns1="http://www.x.com/">
  <return xsi:type="tns:data_warehouse_report">
   <start_row xsi:type="xsd:int">1</start_row>
   <end_row xsi:type="xsd:int">2</end_row>
   <finished xsi:type="xsd:boolean">true</finished>
   <rows xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="tns:data_warehouse_report_row[2]">
    <item xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="xsd:string[3]">
     <item xsi:type="xsd:string">March 12, 2010</item>
     <item xsi:type="xsd:string">recipient3</item>
     <item xsi:type="xsd:string">sample product1</item>
    </item>
    <item xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="xsd:string[0]"></item>
   </rows>
  </return>
 </ns1:Export.GetData>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

请注意以下几行:

<rows xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="tns:data_warehouse_report_row[2]">
<item xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="xsd:string[3]">

WSDL:

<xsd:complexType name="data_warehouse_report">
  <xsd:all>
    <xsd:element name="start_row" type="xsd:int"/>
    <xsd:element name="end_row" type="xsd:int"/>
    <xsd:element name="finished" type="xsd:boolean"/>
    <xsd:element name="rows" type="tns:data_warehouse_report_row_list"/>
  </xsd:all>
</xsd:complexType>

奇怪的是,data_warehouse_report类型将类型行指定为“data_warehouse_report_list”,甚至在响应中都没有使用。

我的大问题是..根据Web服务响应,您将如何创建代理对象data_warehouse_report_row?

我已将其翻译为:

[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.SoapTypeAttribute(Namespace = "http://www.x.com/")]
public partial class data_warehouse_report_row
{
    private string[] itemField;

    public string[] item
    {
        get
        {
            return this.itemField;
        }
        set
        {
            this.itemField = value;
        }
    }
}

但在反序列化时仍然抱怨不正确的数据类型..

例外:

InvalidCastException: "Object cannot be stored in an array of this type."

我尝试使用.NET反射器来调试已编译的程序集(主要是System.Xml.Serialization),但是跟踪结束于生成的程序集创建的读取器由序列化程序创建的...所以我无法确切地弄清楚它试图从哪些数据中投射出来。

有什么想法吗?

0 个答案:

没有答案