Web Services SOAP消息不包括操作名称

um6iljoc  于 2022-11-15  发布在  其他
关注(0)|答案(1)|浏览(148)

我正在使用WebServiceGatewaySupportorg.jvnet.jaxb2.maven2.maven-jaxb2-plugin版本0.15.1与第三方WSDL集成。WSDL在SoapUI上正常工作,但不能直接在Sping Boot 中工作。
在添加了额外的绑定和名称空间声明之后,我的调用仍然会失败,因为Method 'ns2:carsRequest' not implemented: method name or namespace not recognized
我意识到我的代码没有用操作 Package request元素,这意味着下面的消息在SOAP UI中成功,但是在从我的Java代码生成的有效负载中缺少<pai:GetListCars>

<SOAP-ENV:Envelope
    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:pai="http://my-endpoint.com">
    <SOAP-ENV:Header/>
    <SOAP-ENV:Body>
        <pai:GetListCars> <!-- line missing -->
            <ns2:carsRequest xmlns:ns2="http://schemas.xmlsoap.org/soap/encoding/">
                <lang>EN</lang>
            </ns2:carRequest>
        </pai:GetListCars> <!-- line missing -->
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

下面是相应的WSDL:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:apachesoap="http://xml.apache.org/xml-soap"
                  xmlns:impl="http://my-endpoint.com"
                  xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
                  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
                  xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
                  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                  targetNamespace="http://my-endpoint.com">
    <wsdl:types>
        <schema targetNamespace="http://my-endpoint.com"
                xmlns="http://www.w3.org/2001/XMLSchema">
            <import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
            <complexType name="CarsRequest">
                <sequence>
                    <element name="lang" nillable="true" type="soapenc:string"/>
                </sequence>
            </complexType>
            <complexType name="CarsResponse">
                <sequence>
                    <element name="ErrorMessage" nillable="true" type="soapenc:string"/>
                </sequence>
            </complexType>
        </schema>
    </wsdl:types>
    <wsdl:message name="GetListCarsResponse">
        <wsdl:part name="getListCarsReturn" type="impl:CarsResponse"/>
    </wsdl:message>
    <wsdl:message name="GetListCarsRequest">
        <wsdl:part name="carRequest" type="impl:CarsRequest"/>
    </wsdl:message>
    <wsdl:portType name="Garage">
        <wsdl:operation name="GetListCars" parameterOrder="frnreq">
            <wsdl:input message="impl:GetListCarsRequest" name="getListVehiclesRequest"/>
            <wsdl:output message="impl:GetListCarsResponse" name="getListVehiclesResponse"/>
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="GarageSoapBinding"
                  type="impl:Garage">
        <wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation name="GetListCars">
            <wsdlsoap:operation soapAction=""/>
            <wsdl:input name="getListVehiclesRequest">
                <wsdlsoap:body
                        encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
                        namespace="http://my-endpoint.com" use="encoded"/>
            </wsdl:input>
            <wsdl:output name="getListVehiclesResponse">
                <wsdlsoap:body
                        encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
                        namespace="http://my-endpoint.com" use="encoded"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="GarageService">
        <wsdl:port binding="impl:GarageSoapBinding" name="Garage">
            <wsdlsoap:address location="http://localhost:8888"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

我不想更改源WSDL文件,是否有方法构造并添加缺少的行?或者使用不同的库?

f2uvfpb9

f2uvfpb91#

在WSDL的标记中没有GetListCarsResponse和GetListCarsRequest。

jaxb只从模式读取,而不是从整个WSDL读取。

因此,您需要像这样更改schema.xsd文件。再次尝试编译服务器源代码并从服务器获取新的WSDL。要粘贴到客户端源代码中,请编译它,然后调用Soap API。

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://my-endpoint.com"
    xmlns:tns="http://my-endpoint.com"
    elementFormDefault="qualified">
    <xs:import namespace="http://schemas.xmlsoap.org/soap/encoding/" />
    <xs:complexType name="CarsRequest">
        <xs:sequence>
            <xs:element name="lang" nillable="true" type="xs:string" />
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="CarsResponse">
        <xs:sequence>
            <xs:element name="ErrorMessage" nillable="true" type="xs:string" />
        </xs:sequence>
    </xs:complexType>

    <xs:element name="GetListCarsRequest">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="name" type="tns:CarsRequest"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

    <xs:element name="GetListCarsResponse">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="name" type="tns:CarsResponse"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

新的WSDL将如下所示。

<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:sch="http://my-endpoint.com"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:tns="http://my-endpoint.com"
    targetNamespace="http://my-endpoint.com">
    <wsdl:types>
        <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://my-endpoint.com">
            <xs:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
            <xs:complexType name="CarsRequest">
                <xs:sequence>
                    <xs:element name="lang" nillable="true" type="xs:string"/>
                </xs:sequence>
            </xs:complexType>
            <xs:complexType name="CarsResponse">
                <xs:sequence>
                    <xs:element name="ErrorMessage" nillable="true" type="xs:string"/>
                </xs:sequence>
            </xs:complexType>
            <xs:element name="GetListCarsRequest">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="name" type="tns:CarsRequest"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element name="GetListCarsResponse">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="name" type="tns:CarsResponse"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:schema>
    </wsdl:types>
    <wsdl:message name="GetListCarsResponse">
        <wsdl:part element="tns:GetListCarsResponse" name="GetListCarsResponse"></wsdl:part>
    </wsdl:message>
    <wsdl:message name="GetListCarsRequest">
        <wsdl:part element="tns:GetListCarsRequest" name="GetListCarsRequest"></wsdl:part>
    </wsdl:message>
    <wsdl:portType name="Garage">
        <wsdl:operation name="GetListCars">
            <wsdl:input message="tns:GetListCarsRequest" name="GetListCarsRequest"></wsdl:input>
            <wsdl:output message="tns:GetListCarsResponse" name="GetListCarsResponse"></wsdl:output>
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="GarageSoap11" type="tns:Garage">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation name="GetListCars">
            <soap:operation soapAction=""/>
            <wsdl:input name="GetListCarsRequest">
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output name="GetListCarsResponse">
                <soap:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="GarageService">
        <wsdl:port binding="tns:GarageSoap11" name="GarageSoap11">
            <soap:address location="http://localhost:8888/service/garage"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

相关问题