Web Service返回SOAP但属性为空

时间:2013-04-19 06:27:34

标签: c# wcf web-services wsdl

我创建了一个Web服务客户端,编译了一个WSDL,在调用Logon方法(ResponseCode等等为空)后,除了空属性外,一切正常。

我有一条响应SOAP消息:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sas="http://ws.test.com/">
   <soapenv:Header/>
   <soapenv:Body>
      <sas:LogonResponse>
         <SessionID>19790</SessionID>
         <ResponseCode>0</ResponseCode>
         <ResponseMessage>Logon OK</ResponseMessage>
      </sas:LogonResponse>
   </soapenv:Body>
</soapenv:Envelope>

此方法的WSDL部分如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:sas="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://ws.test.com/" xmlns:ns="http://ws.test.com/" targetNamespace="http://ws.test.com/">
    <wsdl:types>
        <sas:schema xmlns:sas="http://www.w3.org/2001/XMLSchema" targetNamespace="http://ws.test.com/" elementFormDefault="qualified">
            <sas:element name="Logon">
                <sas:complexType>
                    <sas:sequence>
                        <sas:element name="Username" type="sas:string" nillable="false"/>
                        <sas:element name="Password" type="sas:string" nillable="false"/>
                    </sas:sequence>
                </sas:complexType>
            </sas:element>
            <sas:element name="LogonResponse">
                <sas:complexType>
                    <sas:sequence>
                        <sas:element name="SessionID" type="sas:long" nillable="false"/>
                        <sas:element name="ResponseCode" type="sas:integer" nillable="false"/>
                        <sas:element name="ResponseMessage" type="sas:string" nillable="false"/>
                    </sas:sequence>
                </sas:complexType>
            </sas:element>
        </sas:schema>
    </wsdl:types>

    <wsdl:message name="LogonRequest">
        <wsdl:part name="Logon" element="tns:Logon"/>
    </wsdl:message>
    <wsdl:message name="LogonResponse">
        <wsdl:part name="LogonResponse" element="tns:LogonResponse"/>
    </wsdl:message>

    <wsdl:portType name="rrrwebservice">
        <wsdl:operation name="Logon">
            <wsdl:input message="tns:LogonRequest"/>
            <wsdl:output message="tns:LogonResponse"/>
        </wsdl:operation>
    </wsdl:portType>

    <wsdl:binding name="mvcBinding" type="tns:rrrwebservice">
        <soap:binding style="document"
            transport="http://schemas.xmlsoap.org/soap/http" />
        <wsdl:operation name="Logon">
            <soap:operation
                soapAction="http://ws.test.com/Logon" />
            <wsdl:input>
                <soap:body use="literal" />
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal" />
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>

    <wsdl:service name="RRRWebService">
        <wsdl:port name="RRRWebService" binding="tns:mvcBinding">
            <soap:address location="http://172.6.2.14:8008/"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

无法弄清楚问题。 我通过在Visual Studio 2008中选择“添加服务引用”来编译它。 任何意见和答案将不胜感激! 感谢。

1 个答案:

答案 0 :(得分:0)

半信息的MS实现对格式非常挑剔。它想要这样的ns:标记符号

watch

我有一个名为OTRS的应用程序的响应,该应用程序是用Perl编写的。它创建了这样的响应:

    <?xml version="1.0" encoding="UTF-8"?>
    <soap:Envelope soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding" xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:soapenc="http://www.w3.org/2003/05/soap-encoding" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <soap:Body>
            <ns2:SessionCreateResponse xmlns:ns2="http://www.otrs.org/TicketConnector/">
                <SessionID>3efVfYNzxB2z8wUKQRPeVYc7K9JddAlf</SessionID>
            </ns2:SessionCreateResponse>
        </soap:Body>
    </soap:Envelope>

MS不会拥有它。与XmlSchemaForm.Unqualified / None混淆不会做任何事情。我不得不在Reference.cs中进行覆盖以重新格式化消息。

    <soap:Envelope soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding" xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:soapenc="http://www.w3.org/2003/05/soap-encoding" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
       <soap:Body>
          <SessionCreateResponse xmlns="http://www.otrs.org/TicketConnector/">
             <SessionID>juFUKqABresNemTCYtPHFiLFWgjJ4QNj</SessionID>
          </SessionCreateResponse>
       </soap:Body>
    </soap:Envelope>