如何让 wsdl 符合 soap 输入

How to have a wsdl conform to the soap input

我们正在将 soap 网络服务从 jetty 更改为 jaxws。目标是保持相同的输入消息。我使用原始的 WSDL 通过 netbeans 创建服务。 WSDL 如下:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://www.mycompany.nl/DcxExpeditieService/v1"
        xmlns:tns="http://www.mycompany.nl/DcxExpeditieService/v1"
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
        xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
    <wsdl:types>
        <xs:schema targetNamespace="http://www.mycompany.nl/DcxExpeditieService/v1"
                xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
            <xs:element name="DcxExpeditie" type="tns:DcxExpeditie"/>
            <xs:complexType name="DcxExpeditie">
                <xs:sequence>
                    <xs:element name="Expeditie" type="tns:Expeditie"/>
                </xs:sequence>
            </xs:complexType>
            <xs:complexType name="Expeditie">
                <xs:sequence>
                    <xs:element name="tag1" type="xs:string"/>
                    <xs:element name="tag2" type="xs:string"/>
                </xs:sequence>
            </xs:complexType>
        </xs:schema>
    </wsdl:types>
    <wsdl:message name="DcxExpeditieRequest">
        <wsdl:part name="DcxExpeditie" type="tns:DcxExpeditie"/>
    </wsdl:message>
    <wsdl:message name="DcxExpeditieResponse">
        <wsdl:part name="DcxExpeditieResponse" type="xs:string"/>
    </wsdl:message>
    <wsdl:portType name="DcxExpeditieServicePortType">
        <wsdl:operation name="DcxExpeditieOperation">
            <wsdl:input message="tns:DcxExpeditieRequest"/>
            <wsdl:output message="tns:DcxExpeditieResponse"/>
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="DcxExpeditieServiceSOAP" type="tns:DcxExpeditieServicePortType">
        <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation name="DcxExpeditieOperation">
            <soap:operation soapAction="http://www.mycompany.nl/DcxExpeditieService/v1/DcxExpeditie"/>
            <wsdl:input>
                <soap:body use="literal" namespace="http://www.mycompany.nl/DcxExpeditieService/v1"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal" namespace="http://www.mycompany.nl/DcxExpeditieService/v1"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="DcxExpeditieService">
        <wsdl:port name="DcxExpeditieServiceSOAP" binding="tns:DcxExpeditieServiceSOAP">
            <soap:address location="https://someserver.mycompany.nl/vbs/dcxexpeditie"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

在 soapui 中使用此 WSDL 时,会产生以下输入示例:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://www.mycompany.nl/DcxExpeditieService/v1">
   <soapenv:Header/>
   <soapenv:Body>
      <v1:DcxExpeditieOperation>
         <DcxExpeditie>
            <v1:Expeditie>
               <v1:tag1>?</v1:tag1>
               <v1:tag2>?</v1:tag2>
            </v1:Expeditie>
         </DcxExpeditie>
      </v1:DcxExpeditieOperation>
   </soapenv:Body>
</soapenv:Envelope>

然而,原来的输入格式是:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://www.mycompany.nl/DcxExpeditieService/v1">
       <soapenv:Header/>
       <soapenv:Body>
          <v1:DcxExpeditie>
                <v1:Expeditie>
                   <v1:tag1>?</v1:tag1>
                   <v1:tag2>?</v1:tag2>
                </v1:Expeditie>
          </v1:DcxExpeditie>
       </soapenv:Body>
    </soapenv:Envelope>

所以没有 DcxExpeditieOperation 标签,v1 命名空间在 DcxExpeditie

前面

这可能吗?如果可以,我该如何实现?

尝试将 SOAP 绑定从 rpc 更改为文档以删除 DcxExpeditieOperation 标签:

<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>

要解决命名空间问题,请参考 DcxExpeditie 元素 insted 类型:

<wsdl:part name="DcxExpeditie" element="tns:DcxExpeditie"/>

更新的 WSDL 文件:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://www.mycompany.nl/DcxExpeditieService/v1"
                  xmlns:tns="http://www.mycompany.nl/DcxExpeditieService/v1"
                  xmlns:xs="http://www.w3.org/2001/XMLSchema"
                  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
                  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
    <wsdl:types>
        <xs:schema targetNamespace="http://www.mycompany.nl/DcxExpeditieService/v1"
                           xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
            <xs:element name="DcxExpeditie" type="tns:DcxExpeditie"/>
            <xs:element name="DcxExpeditieResponse" type="xs:string"/>
            <xs:complexType name="DcxExpeditie">
                <xs:sequence>
                    <xs:element name="Expeditie" type="tns:Expeditie"/>
                </xs:sequence>
            </xs:complexType>
            <xs:complexType name="Expeditie">
                <xs:sequence>
                    <xs:element name="tag1" type="xs:string"/>
                    <xs:element name="tag2" type="xs:string"/>
                </xs:sequence>
            </xs:complexType>
        </xs:schema>
    </wsdl:types>
    <wsdl:message name="DcxExpeditieRequest">
        <wsdl:part name="DcxExpeditie" element="tns:DcxExpeditie"/>
    </wsdl:message>
    <wsdl:message name="DcxExpeditieResponse">
        <wsdl:part name="DcxExpeditieResponse" element="tns:DcxExpeditieResponse" />
    </wsdl:message>
    <wsdl:portType name="DcxExpeditieServicePortType">
        <wsdl:operation name="DcxExpeditieOperation">
            <wsdl:input message="tns:DcxExpeditieRequest"/>
            <wsdl:output message="tns:DcxExpeditieResponse"/>
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="DcxExpeditieServiceSOAP" type="tns:DcxExpeditieServicePortType">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation name="DcxExpeditieOperation">
            <soap:operation soapAction="http://www.mycompany.nl/DcxExpeditieService/v1/DcxExpeditie"/>
            <wsdl:input>
                <soap:body use="literal" />
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal" />
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="DcxExpeditieService">
        <wsdl:port name="DcxExpeditieServiceSOAP" binding="tns:DcxExpeditieServiceSOAP">
            <soap:address location="https://someserver.mycompany.nl/vbs/dcxexpeditie"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>