4

我在调用我的 Java Webservice 时遇到了一些问题。只要我使用原始数据类型,例如字符串、整数等,一切正常。

但是当我尝试使用对象作为参数时,我的 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();
    }

}

测试数据类

public class TestData {
    String testString;
    ... + Setter/Getter for testString
}

我使用生成的 WSDL 使用“Component->Import 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 ,在这种情况下会导致异常。所以很明显,两个世界之间的映射不能正常工作。我尝试更改 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>
4

1 回答 1

5

这是德尔福的错。

您的 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-Encoded SOAP 1.1 Envelope 并使用SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/".

所以你必须在 Delphi 中调整一些选项......

也许 Delphi 不能导入 RPC/Literal?尝试切换到 Document/Literal/Wrapped:

@SOAPBinding(style=SOAPBinding.Style.DOCUMENT, use=SOAPBinding.Use.LITERAL, parameterStyle = ParameterStyle.WRAPPED)
于 2012-12-20T09:21:40.953 回答