我正在努力遇到一些问题,请致电我的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
}
我使用生成的WSDL使用"组件 ->导入WSDL ..."菜单将其导入Delphi。之后,我像这样致电网络服务:
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侧收到的无效,在这种情况下导致例外。因此,显然,两个世界之间的映射无法正常工作。我试图在WSDL导入菜单中更改不同的选项,但似乎无效。我看了Delphi发出的肥皂请求:
<?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>
我从未在这个奇怪的参考概念之前见过。这会造成麻烦吗?或其他人有另一个想法,甚至更好:解决方案:)
预先感谢。
P.S。这是生成的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>
这是Delphi的错。
您的JSR-181/JSR-224注释的接口具有明确的@SOAPBinding(style=SOAPBinding.Style.RPC, use=SOAPBinding.Use.LITERAL)
,并且您生成的WSDL状态清楚地表明它是RPC/LITERAL WEBSERVICE
<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>
delphi然而,使用MultireF值创建了SOAP编码的SOAP 1.1信封,并使用SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
表示。
因此,您必须在Delphi中调整一些选择...
也许Delphi无法导入RPC/字面意思?尝试切换到文档/文字/包装:
@SOAPBinding(style=SOAPBinding.Style.DOCUMENT, use=SOAPBinding.Use.LITERAL, parameterStyle = ParameterStyle.WRAPPED)