![](/img/trans.png)
[英]How does webservice application know soap call for a particular method,without using operation name in soap message?
[英]SOAP message not including operation name
我正在使用WebServiceGatewaySupport
和org.jvnet.jaxb2.maven2.maven-jaxb2-plugin
版本 0.15.1 與第 3 方 WSDL 集成。 WSDL 在 SoapUI 上正常工作,但不能直接在 Spring 引導中工作。
添加額外的綁定和命名空間聲明后,我的調用仍然失敗, Method 'ns2:carsRequest' not implemented: method name or namespace not recognized
。
我意識到我的代碼沒有用操作包裝請求元素,這意味着以下消息在 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 文件,有沒有辦法構造添加缺失的行? 或者也許使用不同的庫?
在您的 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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.