【发布时间】:2010-10-18 17:18:37
【问题描述】:
是否可以根据 WSDL 中的信息查看 Web 服务使用的是 SOAP 1.1 还是 1.2?
【问题讨论】:
标签: web-services soap wsdl
是否可以根据 WSDL 中的信息查看 Web 服务使用的是 SOAP 1.1 还是 1.2?
【问题讨论】:
标签: web-services soap wsdl
SOAP 1.1 使用命名空间http://schemas.xmlsoap.org/wsdl/soap/
SOAP 1.2 使用命名空间http://schemas.xmlsoap.org/wsdl/soap12/
wsdl 可以在同一个wsdl 中同时定义soap 1.1 和soap 1.2 下的操作。如果您需要改进 wsdl 以支持需要 soap 1.2 的新功能(例如 MTOM),这很有用,在这种情况下,您不需要创建新服务,只需改进原始服务即可。
【讨论】:
在 WSDL 中,如果您查看 Binding 部分,您会清楚地看到,如果服务使用的是 soap 1.2,则明确提到了 soap 绑定。请参考以下示例。
<binding name="EmployeeServiceImplPortBinding" type="tns:EmployeeServiceImpl">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="findEmployeeById">
<soap12:operation soapAction=""/>
<input><soap12:body use="literal"/></input>
<output><soap12:body use="literal"/></output>
</operation><operation name="create">
<soap12:operation soapAction=""/>
<input><soap12:body use="literal"/></input>
<output><soap12:body use="literal"/></output>
</operation>
</binding>
如果Web 服务使用soap 1.1,它不会在绑定部分的WSDL 文件中明确定义任何soap 版本。请参考以下示例。
<binding name="EmployeeServiceImplPortBinding" type="tns:EmployeeServiceImpl">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"/>
<operation name="findEmployeeById">
<soap:operation soapAction=""/>
<input><soap:body use="literal" namespace="http://jaxb.ws.jax.samples.chathurangaonline.com/"/></input>
<output><soap:body use="literal" namespace="http://jaxb.ws.jax.samples.chathurangaonline.com/"/></output>
</operation><operation name="create">
<soap:operation soapAction=""/>
<input><soap:body use="literal" namespace="http://jaxb.ws.jax.samples.chathurangaonline.com/"/></input>
<output><soap:body use="literal" namespace="http://jaxb.ws.jax.samples.chathurangaonline.com/"/></output>
</operation>
</binding>
如何确定 SOAP 消息的 SOAP 版本?
但请记住,这不是很推荐的方法来确定您的 Web 服务使用的 soap 版本。可以使用以下方法之一确定soap消息的版本。
1.检查soap消息的命名空间
SOAP 1.1 namespace : http://schemas.xmlsoap.org/soap/envelope
SOAP 1.2 namespace : http://www.w3.org/2003/05/soap-envelope
2。检查soap消息的传输绑定信息(http头信息)
SOAP 1.1:上下文类型的用户文本/xml
POST /MyService HTTP/1.1
Content-Type: text/xml; charset="utf-8"
Content-Length: xxx
SOAPAction: "urn:uuid:myaction"
SOAP 1.2:上下文类型的用户应用程序/soap+xml
POST /MyService HTTP/1.1
Content-Type: application/soap+xml; charset="utf-8"
Content-Length: xxx
SOAPAction: "urn:uuid:myaction"
3.使用 SOAP 错误信息
两个版本之间的 SOAP 错误消息的结构不同。
【讨论】:
soap 前缀是 http://schemas.xmlsoap.org/wsdl/soap/。引用 1.2 的 soap12 前缀是 http://schemas.xmlsoap.org/wsdl/soap12/。无论前缀名称是什么(甚至可以是foo 或bar),只要看看它解析的是什么命名空间。
我找到了这个页面
http://schemas.xmlsoap.org/wsdl/soap12/soap12WSDL.htm
这表示 Soap 1.2 使用新的命名空间 http://schemas.xmlsoap.org/wsdl/soap12/
它位于“SOAP 1.1 的 WSDL 1.1 绑定扩展”中。
【讨论】:
是的,您通常可以根据 WSDL 查看支持的 SOAP 版本。
看看Demo web service WSDL。它有一个对 soap12 命名空间的引用,表明它支持 SOAP 1.2。如果不存在,那么假设该服务仅支持 SOAP 1.1,您可能是安全的。
【讨论】:
在 binding-element 中找到了 transport-attribute,它告诉我们这是 SOAP 1.1 HTTP 绑定的 WSDL 1.1 绑定。
例如
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
【讨论】: