如何在 wsdl 中为输入和输出参数提供相同的元素?

How give same element for input and output parameter in wsdl?

我有 aa.xsd 如下。

<?xml version="1.0" encoding="UTF-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://wwwtest.com/test" xmlns:abc="http://wwwtest.com/test">

    <xs:simpleType name="APP_TYPE">
        <xs:restriction base="xs:string">
            <xs:enumeration value="ABC" />
            <xs:enumeration value="DEF" />
        </xs:restriction>
    </xs:simpleType>

    <xs:element name="RootElement" type="abc:RootElementType" />
    <xs:complexType name="RootElementType">
        <xs:choice>
            <xs:sequence>
                <xs:element ref="abc:UserRequest" />
                <xs:any minOccurs="0" />
            </xs:sequence>
            <xs:sequence>
                <xs:element ref="abc:UserResponse" />
                <xs:any minOccurs="0" />
            </xs:sequence>
        </xs:choice>
    </xs:complexType>

    <xs:element name="UserRequest" type="abc:UserRequestType" />
    <xs:complexType name="UserRequestType">
        <xs:sequence>
            <xs:element name="UserLoginName" type="xs:string" />
            <xs:element ref="abc:VendorApp" />
        </xs:sequence>
    </xs:complexType>

    <xs:element name="VendorApp" type="abc:VendorAppType" />
    <xs:complexType name="VendorAppType">
        <xs:sequence>
            <xs:element name="AppName" type="abc:APP_TYPE" />
        </xs:sequence>
    </xs:complexType>

    <xs:element name="UserResponse" type="abc:UserResponseType" />

    <xs:complexType name="UserResponseType">
        <xs:sequence>
            <xs:element name="SessionKey" type="xs:string" />
            <xs:element name="SessionKeyExpDate" type="xs:date" minOccurs="0" />
        </xs:sequence>
    </xs:complexType>
</xs:schema>

编写 WSDL 如下。

<?xml version="1.0" encoding="UTF-8"?><wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="ABCcomacc" targetNamespace="http://wwwtest.com/test/com/acc/" xmlns:abc="http://wwwtest.com/test" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:ws="http://wwwtest.com/test/com/acc/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

    <wsdl:types>
        <xsd:schema>
            <xsd:import namespace="http://wwwtest.com/test" schemaLocation="aaa.xsd"/>
        </xsd:schema>
    </wsdl:types>

    <wsdl:message name="xyzSearchRequest">
        <wsdl:part element="abc:RootElement" name="parameters"/>
    </wsdl:message>

    <wsdl:message name="xyzSearchResponse">
        <wsdl:part element="abc:RootElement" name="parameters"/>
    </wsdl:message>

    <wsdl:portType name="ABCcomacc">
        <wsdl:operation name="xyzSearch">
            <wsdl:input message="ws:xyzSearchRequest"/>
            <wsdl:output message="ws:xyzSearchResponse"/>
        </wsdl:operation>
    </wsdl:portType>

    <wsdl:binding name="ABCcomaccSOAP12" type="ws:ABCcomacc">

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

        <wsdl:operation name="xyzSearch">
            <soap12:operation soapAction="http://wwwtest.com/test/com/acc/xyzSearch"/>
            <wsdl:input>
                <soap12:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap12:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>

    </wsdl:binding>

    <wsdl:service name="ABCcomacc">
        <wsdl:port binding="ws:ABCcomaccSOAP12" name="ABCcomaccSOAP12">
            <soap12:address location="http://localhost:9080/ABCcomacc/ABCcomacc"/>
        </wsdl:port>
    </wsdl:service>

</wsdl:definitions>

我的骨架 class 实现生成如下。

@javax.jws.WebService (endpointInterface="com.wwwtest.test.com.acc.ABCcomacc", targetNamespace="http://wwwtest.com/test/com/acc/", serviceName="ABCcomacc", portName="ABCcomaccSOAP12", wsdlLocation="WEB-INF/wsdl/LTCCommonAccord.wsdl")
@javax.xml.ws.BindingType (value=javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING)
public class ABCcomaccSOAP12Impl{

    public void xyzSearch(Holder<RootElementType> parameters) {
        // TODO Auto-generated method stub
        return;
    }

}

此方法 return 类型为 void,方法参数为 Holder<RootElementType> parameters,但 return 类型和方法参数应为 RootElementType。

有人知道我为什么会得到这个输出吗?请给我建议... 我正在使用 JAX-WS。

请求和响应元素具有不同的名称,如下所示。

<wsdl:message name="xyzSearchRequest"> <wsdl:part element="abc:RootElement" name="reqparams"/> </wsdl:message> <wsdl:message name="xyzSearchResponse"> <wsdl:part element="abc:RootElement" name="respparams"/> </wsdl:message>

您如何生成绑定?如果您使用 Maven 的 wsimport 目标,则编写一个绑定文件并在绑定部分添加以下内容。
<enableWrapperStyle>false</enableWrapperStyle>