我必须基于 WSDL 文件创建特定的 SOAP 请求消息。我正在使用 SOAP UI 从 WSDL 创建 SOAP 请求。
SOAP 请求应如下所示:
<?xml version="1.0"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
SOAP-ENV:encodingstyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Header>
<username>xxxx</username>
<password>xxxx</password>
<MaxOrders>1</MaxOrders>
<xmlVers>1</xmlVers>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<m:getNewOrders xmlns:m= "urn:https://xxx.yyy.co.uk/b2b/soap/soap:getNewOrders/">
</m:getNewOrders>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
我有以下 WSDL:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions
xmlns:m="https://xxx.yyy.co.uk/b2b/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
name="xxxOrders"
targetNamespace="https://xxx.yyy.co.uk/b2b/">
<wsdl:types>
<xsd:schema targetNamespace="https://xxx.yyy.co.uk/b2b/">
<xsd:element name="Envelope">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Header"/>
<xsd:element name="Body"/>
</xsd:sequence>
<xsd:attribute name="encodingstyle" type="xsd:anyURI" form="qualified" use="required" />
</xsd:complexType>
</xsd:element>
<xsd:element name="Header">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="username" type="xsd:NCName" form="unqualified" />
<xsd:element name="password" type="xsd:integer" form="unqualified" />
<xsd:element name="MaxOrders" type="xsd:integer" form="unqualified" />
<xsd:element name="xmlVers" type="xsd:integer" form="unqualified" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Body">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="m:getNewOrders" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="getNewOrders">
<xsd:complexType />
</xsd:element>
</xsd:schema>
</wsdl:types>
<wsdl:message name="getNewOrders">
<wsdl:part element="m:getNewOrders" name="parameters"/>
</wsdl:message>
<wsdl:portType name="xxxOrders">
<wsdl:operation name="getNewOrders">
<wsdl:input message="m:getNewOrders"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="xxxOrdersSOAP" type="m:xxxOrders">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getNewOrders">
<soap:operation soapAction="urn:https://xxx.yyy.co.uk/b2b/soap/soap:getNewOrders/"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="xxxOrders">
<wsdl:port binding="m:xxxOrdersSOAP" name="xxxOrdersSOAP">
<soap:address location="https://xxx.yyy.co.uk/b2b/soap/soap_orders.asp"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
但是当我获取该 WSDL 并将其导入 SOAP UI 中时,SOAP 请求消息看起来与我期望的不同:
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:b2b="https://xxx.yyy.co.uk/b2b/">
<soapenv:Header/>
<soapenv:Body>
<b2b:getNewOrders/>
</soapenv:Body>
</soapenv:Envelope>
例如,我的 Header
元素为空。我认为 getNewOrders 没问题,因为它绑定(bind)到 xmlns:b2b,所以我不需要元素 getNewOrders 中的命名空间。我说得对吗?
有人可以指出我必须在 WSDL 中修复什么吗?我迷路了。
最佳答案
您对命名空间没问题,问题是您没有定义 header 部分。现在,即使您这样做,我也不知道您的工具是否会考虑...但绝对,就接口(interface)定义而言,这是您必须做的。
搜索“wsdlsoap header example”或类似内容应该会产生很多命中,例如 this one .
要点是:
- 您的输入部分应定义与 header 相关的部分。
<wsdl:message name="getNewOrders"> <wsdl:part element="m:getNewOrders" name="parameters"/> <wsdl:part element="m:Header" name="header"/> </wsdl:message>
- 您需要将该 header 部分绑定(bind)到 SOAP header
<wsdl:operation name="getNewOrders"> <soap:operation soapAction="urn:https://xxx.yyy.co.uk/b2b/soap/soap:getNewOrders/"/> <wsdl:input name="getNewOrders"> <wsdlsoap:header message="getNewOrders" part="header" use="literal"/> <wsdlsoap:body use="literal" parts="parameters"/> </wsdl:input> <wsdl:output> <soap:body use="literal"/> </wsdl:output> </wsdl:operation>
现在,我还没有检查前缀(您应该有一个与 WSDL 的 targetNamespace 相匹配的默认 namespace ,以便上述内容可以在没有前缀的情况下工作,等等),也没有尝试为您重写 WSDL...但这是从根本上讲,您如何指定 header :您的输入有多个部分,在 SOAP 中,一个部分位于 header 中,另一个部分位于正文中。
关于soap - 为特定 SOAP 请求创建 WSDL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21046537/