代码之家  ›  专栏  ›  技术社区  ›  vico

SOAP1.1或SOAP1.2

  •  3
  • vico  · 技术社区  · 10 年前

    gSOAP库生成了两条请求消息:

    1.

    POST http://localhost:8998/Service1.svc/ HTTP/1.1
    Host: localhost:8998
    User-Agent: gSOAP/2.8
    Content-Type: application/soap+xml; charset=utf-8; action="http://tempuri.org/IService1/GetData"
    Content-Length: 536
    Connection: close
    SOAPAction: "http://tempuri.org/IService1/GetData"
    
    <?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns4="http://schemas.datacontract.org/2004/07/WcfService2" xmlns:ns3="http://schemas.microsoft.com/2003/10/Serialization/" xmlns:ns1="http://tempuri.org/"><SOAP-ENV:Body><ns1:GetData><ns1:value>55</ns1:value></ns1:GetData></SOAP-ENV:Body></SOAP-ENV:Envelope>
    

    2.

    POST http://localhost:8998/Service1.svc/ HTTP/1.1
    Host: localhost:8998
    User-Agent: gSOAP/2.8
    Content-Type: text/xml; charset=utf-8
    Content-Length: 538
    Connection: close
    SOAPAction: "http://tempuri.org/IService1/GetData"
    
    <?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns4="http://schemas.datacontract.org/2004/07/WcfService2" xmlns:ns3="http://schemas.microsoft.com/2003/10/Serialization/" xmlns:ns1="http://tempuri.org/"><SOAP-ENV:Body><ns1:GetData><ns1:value>55</ns1:value></ns1:GetData></SOAP-ENV:Body></SOAP-ENV:Envelope>
    

    它们是什么类型的信息 SOAP 1.1 SOAP 1.2 ?

    默认情况下,第一条消息由wsdl2h和soapcpp2生成的代理类格式化。此消息请求失败。代理生成了第二条消息,其中包含已更改的命名空间:

    从…起

    {"SOAP-ENV", "http://www.w3.org/2003/05/soap-envelope", "http://schemas.xmlsoap.org/soap/envelope/", NULL},
    

    {"SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/","http://schemas.xmlsoap.org/soap/envelope/",NULL},
    

    而且效果很好。为什么我需要更改命名空间以使其正常工作?为什么gSOAP工具不能生成正确的命名空间?

    WSDL:

    <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:tns="http://tempuri.org/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" name="Service1" targetNamespace="http://tempuri.org/">
    <wsdl:types>
    <xsd:schema targetNamespace="http://tempuri.org/Imports">
    <xsd:import schemaLocation="http://localhost:8998/Service1.svc?xsd=xsd0" namespace="http://tempuri.org/"/>
    <xsd:import schemaLocation="http://localhost:8998/Service1.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>
    <xsd:import schemaLocation="http://localhost:8998/Service1.svc?xsd=xsd2" namespace="http://schemas.datacontract.org/2004/07/WcfService2"/>
    </xsd:schema>
    </wsdl:types>
    <wsdl:message name="IService1_GetData_InputMessage">
    <wsdl:part name="parameters" element="tns:GetData"/>
    </wsdl:message>
    <wsdl:message name="IService1_GetData_OutputMessage">
    <wsdl:part name="parameters" element="tns:GetDataResponse"/>
    </wsdl:message>
    <wsdl:message name="IService1_GetDataUsingDataContract_InputMessage">
    <wsdl:part name="parameters" element="tns:GetDataUsingDataContract"/>
    </wsdl:message>
    <wsdl:message name="IService1_GetDataUsingDataContract_OutputMessage">
    <wsdl:part name="parameters" element="tns:GetDataUsingDataContractResponse"/>
    </wsdl:message>
    <wsdl:portType name="IService1">
    <wsdl:operation name="GetData">
    <wsdl:input wsaw:Action="http://tempuri.org/IService1/GetData" message="tns:IService1_GetData_InputMessage"/>
    <wsdl:output wsaw:Action="http://tempuri.org/IService1/GetDataResponse" message="tns:IService1_GetData_OutputMessage"/>
    </wsdl:operation>
    <wsdl:operation name="GetDataUsingDataContract">
    <wsdl:input wsaw:Action="http://tempuri.org/IService1/GetDataUsingDataContract" message="tns:IService1_GetDataUsingDataContract_InputMessage"/>
    <wsdl:output wsaw:Action="http://tempuri.org/IService1/GetDataUsingDataContractResponse" message="tns:IService1_GetDataUsingDataContract_OutputMessage"/>
    </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="BasicHttpBinding_IService1" type="tns:IService1">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="GetData">
    <soap:operation soapAction="http://tempuri.org/IService1/GetData" style="document"/>
    <wsdl:input>
    <soap:body use="literal"/>
    </wsdl:input>
    <wsdl:output>
    <soap:body use="literal"/>
    </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="GetDataUsingDataContract">
    <soap:operation soapAction="http://tempuri.org/IService1/GetDataUsingDataContract" style="document"/>
    <wsdl:input>
    <soap:body use="literal"/>
    </wsdl:input>
    <wsdl:output>
    <soap:body use="literal"/>
    </wsdl:output>
    </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="Service1">
    <wsdl:port name="BasicHttpBinding_IService1" binding="tns:BasicHttpBinding_IService1">
    <soap:address location="http://localhost:8998/Service1.svc"/>
    </wsdl:port>
    </wsdl:service>
    </wsdl:definitions>
    
    2 回复  |  直到 10 年前
        1
  •  1
  •   Community Mohan Dere    9 年前

    This helpful SO post 声明SOAP 1.1使用此命名空间:

    http://schemas.xmlsoap.org/soap/envelope/
    

    而SOAP 1.2使用此命名空间:

    http://www.w3.org/2003/05/soap-envelope
    

    你的 第一 因此,消息似乎来自SOAP 1.2,而您的 第二 消息似乎来自SOAP 1.1。由于第一条消息失败,第二条消息通过,所以看起来您使用的是符合SOAP 1.1的服务。

        2
  •  0
  •   Kuker    8 年前

    很多时候,当您看到

    Content-Type: application/soap+xml; charset=utf-8; action="address"

    SOAP 1.1使用 Content-Type: text/xml; charset=utf-8

    推荐文章