首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Java CFX Webservice和Delphi 2010

Java CFX Webservice和Delphi 2010
EN

Stack Overflow用户
提问于 2012-12-20 17:12:18
回答 1查看 955关注 0票数 4

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

但是当我尝试使用对象作为参数时,我的java方法只接收null。因此,映射似乎不起作用。我举了一个简单的例子:

用于Webservice的Java接口

代码语言:javascript
复制
@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实现

代码语言:javascript
复制
@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类

代码语言:javascript
复制
public class TestData {
    String testString;
    ... + Setter/Getter for testString
}

我使用"Component->Import WSDL...“将生成的WSDL导入到Delphi中。菜单。然后,我像这样调用Webservice:

代码语言:javascript
复制
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请求:

代码语言:javascript
复制
<?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>

我以前从未见过这种奇怪的引用概念。这会造成麻烦吗?或者其他人有其他想法,甚至更好:一个解决方案:)

提前谢谢。

附注:生成的WSDL如下:

代码语言:javascript
复制
<?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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-12-20 17:21:41

这是Delphi的错。

您的带注释的接口具有显式的@SOAPBinding(style=SOAPBinding.Style.RPC, use=SOAPBinding.Use.LITERAL),并且您生成的WSDL清楚地声明它是RPC/文本WebService

代码语言:javascript
复制
  <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编码的SOAP1.1信封,并使用SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"表示它。

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

也许Delphi不能导入RPC/文本?尝试切换到文档/文本/包装:

代码语言:javascript
复制
@SOAPBinding(style=SOAPBinding.Style.DOCUMENT, use=SOAPBinding.Use.LITERAL, parameterStyle = ParameterStyle.WRAPPED)
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13968646

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档