为特定的SOAP请求创建WSDL

时间:2014-01-10 14:16:18

标签: soap xsd wsdl

我必须基于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是可以的,因为它绑定到xmlns:b2b所以我不需要元素getNewOrders中的命名空间。我是对的吗?

有人可以指出我在WSDL中需要解决的问题吗?我迷路了。

1 个答案:

答案 0 :(得分:1)

您对命名空间没问题,问题是您没有定义标题部分。现在,即使你这样做,我也不知道你的工具是否会考虑......但是就接口定义而言,这肯定是你必须要做的。

搜索“wsdl soap header example”或类似内容会产生很多匹配,例如this one

关键点是:

  • 您的输入部分应定义与标题相关的部分。
 <wsdl:message name="getNewOrders">
     <wsdl:part element="m:getNewOrders" name="parameters"/>
     <wsdl:part element="m:Header" name="header"/>
 </wsdl:message>
  • 您需要将该标头部分绑定到SOAP标头
<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匹配,以便上面没有前缀等工作),也没试过为你重写WSDL ......但这是从根本上说你如何指定标题:你的输入有多个部分,在SOAP中,一个在标题中,另一个在主体中。