Java CFX Webservice和Delphi 2010
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Java CFX Webservice和Delphi 2010,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含5199字,纯文字阅读大概需要8分钟。
内容图文
![Java CFX Webservice和Delphi 2010](/upload/InfoBanner/zyjiaocheng/800/4278dca2b0b148f98aa37c93db90b75d.jpg)
我正在努力解决调用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();
}
}
TestData类
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>
我从未在这个奇怪的参考概念之前看到过.这会引起麻烦吗?或者其他人有另一个想法甚至更好:一个解决方案:)
提前致谢.
附:这是生成的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>
解决方法:
这是德尔福的错.
您的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)
内容总结
以上是互联网集市为您收集整理的Java CFX Webservice和Delphi 2010全部内容,希望文章能够帮你解决Java CFX Webservice和Delphi 2010所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。