Java Web サービスの呼び出しに問題があります。文字列、整数などのプリミティブ データ型を使用している限り、すべて正常に動作します。
しかし、オブジェクトをパラメーターとして使用しようとすると、Java メソッドは null しか受け取りません。そのため、マッピングは機能していないようです。簡単な例を挙げます:
Web サービスの Java インターフェイス
@WebService(name="TestService", targetNamespace=CNAPBackOffice.NAMESPACE_SERVICES)
@SOAPBinding(style=SOAPBinding.Style.RPC, use=SOAPBinding.Use.LITERAL)
public interface TestService {
@WebMethod(operationName="sendComplexType")
@WebResult(name="okString")
public String sendComplexType(TestData data);
}
Java 実装
@WebService(endpointInterface = "lu.ciss.backoffice.cnap.services.TestService",
portName = "TestEndpoint", serviceName = "TestService",
targetNamespace = CNAPBackOffice.NAMESPACE_SERVICES)
public class TestServiceImpl implements TestService {
@Override
public String sendComplexType(TestData data) {
return data.getTestString();
}
}
TestData クラス
public class TestData {
String testString;
... + Setter/Getter for testString
}
「Component->Import WSDL...」メニューを使用して、生成された WSDL を Delphi にインポートします。その後、次のように Webservice を呼び出します。
procedure TFRM_Test.TestClick(Sender: TObject);
var
Service: TestService;
data: TestData;
result: String;
begin
Service := GetTestService(true);
data := TestData.Create;
data.testString := 'Bla';
result := Service.sendComplexType(data);
ShowMessage(result);
end;
前に言ったように、Java 側は null を受け取り、この場合は例外が発生します。したがって、2 つの世界の間のマッピングが正しく機能していないことは明らかです。WSDL インポート メニューのさまざまなオプションを変更しようとしましたが、何も機能しないようです。Delphi によって発行された SOAP リクエストを調べました。
<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:NS2="http://cnap.backoffice.ciss.lu/services">
<NS1:sendComplexType xmlns:NS1="http://cnap.backoffice.ciss.lu/services">
<arg0 href="#1"/>
</NS1:sendComplexType>
<NS2:testData id="1" xsi:type="NS2:testData">
<testString xsi:type="xsd:string">Bla</testString>
</NS2:testData>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
私は参照のこの奇妙な概念の前に見たことがありません. これが原因でしょうか?または、他の誰かが別のアイデア、またはさらに良いアイデアを持っていますか:解決策:)
前もって感謝します。
PS 生成された WSDL は次のとおりです。
<?xml version="1.0" ?><wsdl:definitions name="TestService" targetNamespace="http://cnap.backoffice.ciss.lu/services" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://cnap.backoffice.ciss.lu/services" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<xs:schema targetNamespace="http://cnap.backoffice.ciss.lu/services" version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="testData">
<xs:sequence>
<xs:element minOccurs="0" name="testString" type="xs:string"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="sendComplexType">
<wsdl:part name="arg0" type="tns:testData">
</wsdl:part>
</wsdl:message>
<wsdl:message name="sendComplexTypeResponse">
<wsdl:part name="okString" type="xsd:string">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="TestService">
<wsdl:operation name="sendComplexType">
<wsdl:input message="tns:sendComplexType" name="sendComplexType">
</wsdl:input>
<wsdl:output message="tns:sendComplexTypeResponse" name="sendComplexTypeResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="TestServiceSoapBinding" type="tns:TestService">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"></soap:binding>
<wsdl:operation name="sendComplexType">
<soap:operation soapAction="" style="rpc"></soap:operation>
<wsdl:input name="sendComplexType">
<soap:body namespace="http://cnap.backoffice.ciss.lu/services" use="literal"></soap:body>
</wsdl:input>
<wsdl:output name="sendComplexTypeResponse">
<soap:body namespace="http://cnap.backoffice.ciss.lu/services" use="literal"></soap:body>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="TestService">
<wsdl:port binding="tns:TestServiceSoapBinding" name="TestEndpoint">
<soap:address location="http://localhost:7777/CNAP_BackOffice/services/TestService"></soap:address>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>