Webservice代理返回一个空数组,但soap响应有效

时间:2016-12-05 23:02:16

标签: c# web-services soap wsdl wcf-interoperability

我正在尝试从c#windows客户端使用php webservice。我无权访问服务代码。我修改了wsdl以生成代理类。当我调用返回字符串的check_connect()时,一切正常。当我调用gettables()返回一个复杂类型的数组时,我得到一个空数组。它可能与序列化有关,但我无法找到问题。

这是Refernce.cs自动生成代码的一部分。

    [TraceExtensionAttribute(LogType.RequestReponse, "C:\\Log\\MyReq.log", "C:\\Log\\MyRes.log")]
    [System.Web.Services.Protocols.SoapRpcMethodAttribute("http://dhmos-delfon.governing.gr/soap.php/gettables", 
        RequestNamespace="http://dhmos-delfon.governing.gr:10080/soap.php", 
        ResponseNamespace="http://dhmos-delfon.governing.gr:10080/soap.php", 
        Use=System.Web.Services.Description.SoapBindingUse.Literal)]
    [return: System.Xml.Serialization.XmlArrayAttribute("return")]
    [return: System.Xml.Serialization.XmlArrayItemAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=false)]
    public getapp[] gettables(string Username, string Password, string lang) {
        object[] results = this.Invoke("gettables", new object[] {
                    Username,
                    Password,
                    lang});
        return ((getapp[])(results[0]));
    }

        [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.6.1586.0")]
[System.SerializableAttribute()]
//[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:governing_soap")]
public partial class getapp {

    private string appField;

    private string titleField;

    private gettable[] tablesField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public string app {
        get {
            return this.appField;
        }
        set {
            this.appField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public string title {
        get {
            return this.titleField;
        }
        set {
            this.titleField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlArrayAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    [System.Xml.Serialization.XmlArrayItemAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=false)]
    public gettable[] tables {
        get {
            return this.tablesField;
        }
        set {
            this.tablesField = value;
        }
    }
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.6.1586.0")]
[System.SerializableAttribute()]
//[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:governing_soap")]
public partial class gettable {

    private string tableField;

    private string titleField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public string table {
        get {
            return this.tableField;
        }
        set {
            this.tableField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public string title {
        get {
            return this.titleField;
        }
        set {
            this.titleField = value;
        }
    }
}

这是我wsdl的一部分

<?xml version="1.0" encoding="utf-8"?>
<definitions 
  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="urn:governing_soap" 
  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
  xmlns="http://schemas.xmlsoap.org/wsdl/" 
  targetNamespace="urn:governing_soap">
<types>
<xsd:schema targetNamespace="urn:governing_soap">
 <xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/" schemaLocation="http://schemas.xmlsoap.org/soap/encoding/" />
 <xsd:import namespace="http://schemas.xmlsoap.org/wsdl/" />
 <xsd:complexType name="gettable">
  <xsd:all>
   <xsd:element name="table" type="xsd:string"/>
   <xsd:element name="title" type="xsd:string"/>
  </xsd:all>
 </xsd:complexType>
 <xsd:complexType name="tables">
   <xsd:sequence>
   <xsd:element name="gettable" type="tns:gettable" minOccurs="0" maxOccurs="unbounded"/>
  </xsd:sequence>
 </xsd:complexType>
 <xsd:complexType name="getapp">
  <xsd:all>
   <xsd:element name="app" type="xsd:string"/>
   <xsd:element name="title" type="xsd:string"/>
   <xsd:element name="tables" type="tns:tables"/>
  </xsd:all>
 </xsd:complexType>
 <xsd:complexType name="getapps">
   <xsd:sequence>
    <xsd:element name="getapp" type="tns:getapp" minOccurs="0" maxOccurs="unbounded"/>
  </xsd:sequence>
 </xsd:complexType>
</xsd:schema>
</types>
<message name="check_connectRequest"></message>
<message name="check_connectResponse">
  <part name="return" type="xsd:string" /></message>
<message name="gettablesRequest">
  <part name="Username" type="xsd:string" />
  <part name="Password" type="xsd:string" />
  <part name="lang" type="xsd:string" /></message>
<message name="gettablesResponse">
  <part name="return" type="tns:getapps" /></message>
<portType name="governing_soapPortType">
  <operation name="check_connect">
    <input message="tns:check_connectRequest"/>
    <output message="tns:check_connectResponse"/>
  </operation>
  <operation name="gettables">
    <input message="tns:gettablesRequest"/>
    <output message="tns:gettablesResponse"/>
  </operation>
</portType>
<binding name="governing_soapBinding" type="tns:governing_soapPortType">
  <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
  <operation name="check_connect">
    <soap:operation soapAction="http://dhmos-delfon.governing.gr/soap.php/check_connect" style="rpc"/>
    <input><soap:body use="literal" namespace="http://dhmos-delfon.governing.gr:10080/soap.php" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input>
    <output><soap:body use="literal" namespace="http://dhmos-delfon.governing.gr:10080/soap.php" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output>
  </operation>
  <operation name="gettables">
    <soap:operation soapAction="http://dhmos-delfon.governing.gr/soap.php/gettables" style="rpc"/>
    <input><soap:body use="literal" namespace="http://dhmos-delfon.governing.gr:10080/soap.php" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input>
    <output><soap:body use="literal" namespace="http://dhmos-delfon.governing.gr:10080/soap.php" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output>
  </operation>
<service name="governing_soap">
  <port name="governing_soapPort" binding="tns:governing_soapBinding">
    <soap:address location="http://dhmos-delfon.governing.gr:10080/soap.php"/>
  </port>
</service>
</definitions>

这是我得到的回应。

<?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="urn:governing_soap">
    <SOAP-ENV:Body>
        <ns1:gettablesResponse
            xmlns:ns1="http://dhmos-delfon.governing.gr:10080/soap.php">
            <return xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="tns:getapp[2]">
                <item xsi:type="tns:getapp">
                    <app xsi:type="xsd:string">organize</app>
                    <title xsi:type="xsd:string">organize</title>
                    <tables xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="tns:gettable[3]">
                        <item xsi:type="tns:gettable">
                            <table xsi:type="xsd:string">chart</table>
                            <title xsi:type="xsd:string">chart</title>
                        </item>
                        <item xsi:type="tns:gettable">
                            <table xsi:type="xsd:string">chart_users</table>
                            <title xsi:type="xsd:string">chart_users</title>
                        </item>
                        <item xsi:type="tns:gettable">
                            <table xsi:type="xsd:string">diavgeia_units</table>
                            <title xsi:type="xsd:string">diavgeia_units</title>
                        </item>
                    </tables>
                </item>
                <item xsi:type="tns:getapp">
                    <app xsi:type="xsd:string">protocol</app>
                    <title xsi:type="xsd:string">protocol</title>
                    <tables xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="tns:gettable[2]">
                        <item xsi:type="tns:gettable">
                            <table xsi:type="xsd:string">protocol_chart_users</table>
                            <title xsi:type="xsd:string">protocol_chart_users</title>
                        </item>
                        <item xsi:type="tns:gettable">
                            <table xsi:type="xsd:string">protocol_ex_document</table>
                            <title xsi:type="xsd:string">protocol_ex_document</title>
                        </item>
                    </tables>
                </item>
            </return>
        </ns1:gettablesResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

1 个答案:

答案 0 :(得分:0)

我最终使用SoapUIFiddler等应用来测试网络服务并捕获http流量。然后我自己做了序列化。