国内最全IT社区平台 联系我们 | 收藏本站
华晨云阿里云优惠2
您当前位置:首页 > php开源 > php教程 > Java开发WebServices传递pojo提示参数不匹配的问题

Java开发WebServices传递pojo提示参数不匹配的问题

来源:程序员人生   发布时间:2015-01-28 08:52:54 阅读次数:2678次

webservices服务用Java开发的时候,参数为基本数据类型是没有甚么问题的。

但是如果是传递pojo,也就是java对象,可能你会遇到参数不匹配的问题。


webservices接口暴露出来以后肯定是1个wsdl文件,看到网上很多文章说“webservices传递pojo的时候,提示参数不匹配,很多人解决方式是把接口和pojo放在1起就好用了。这个实际上是表象”

This XML file does not appear to have any style information associated with it. The document tree is shown below. <wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://d.c.b.a/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" name="TestwsImpl1Service" targetNamespace="http://d.c.b.a/"> <wsdl:types> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://d.c.b.a/" elementFormDefault="unqualified" targetNamespace="http://d.c.b.a/" version="1.0"> <xs:element name="updatePerson" type="tns:updatePerson"/> <xs:element name="updatePersonResponse" type="tns:updatePersonResponse"/> <xs:complexType name="updatePerson"> <xs:sequence> <xs:element minOccurs="0" name="arg0" type="tns:person"/> </xs:sequence> </xs:complexType> <xs:complexType name="person"> <xs:sequence> <xs:element name="age" type="xs:int"/> <xs:element minOccurs="0" name="name" type="xs:string"/> </xs:sequence> </xs:complexType> <xs:complexType name="updatePersonResponse"> <xs:sequence> <xs:element minOccurs="0" name="return" type="tns:person"/> </xs:sequence> </xs:complexType> </xs:schema> </wsdl:types> <wsdl:message name="updatePersonResponse"> <wsdl:part element="tns:updatePersonResponse" name="parameters"></wsdl:part> </wsdl:message> <wsdl:message name="updatePerson"> <wsdl:part element="tns:updatePerson" name="parameters"></wsdl:part> </wsdl:message> <wsdl:portType name="TestwsImpl1"> <wsdl:operation name="updatePerson"> <wsdl:input message="tns:updatePerson" name="updatePerson"></wsdl:input> <wsdl:output message="tns:updatePersonResponse" name="updatePersonResponse"></wsdl:output> </wsdl:operation> </wsdl:portType> <wsdl:binding name="TestwsImpl1ServiceSoapBinding" type="tns:TestwsImpl1"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="updatePerson"> <soap:operation soapAction="" style="document"/> <wsdl:input name="updatePerson"> <soap:body use="literal"/> </wsdl:input> <wsdl:output name="updatePersonResponse"> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="TestwsImpl1Service"> <wsdl:port binding="tns:TestwsImpl1ServiceSoapBinding" name="TestwsImpl1Port"> <soap:address location="http://localhost:888/test1"/> </wsdl:port> </wsdl:service> </wsdl:definitions>

以上是我开发的1个webservices接口对应的wsdl文件, 文件中我的targetNamespace是
targetNamespace="http://d.c.b.a/"


也就是说 我的webservices服务真个person和targetNamespace不是1样的路径。


------------------------------------------------------------------------------------------------------------------------


我们再来开发1个客户端程序。



客户真个person路径为服务端targetNamespace是对应关系。


这类情况下,传递pojo才能调通。


总结:webservices服务真个pojo路径无所谓在这里,只要客户端pojo包路径和wsdl文件中targetNamespace对应,就能够调用通过。


网上说:客户端必须把pojo和接口声明放在1起的结论实际上是不对的。

生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠
程序员人生
------分隔线----------------------------
分享到:
------分隔线----------------------------
关闭
程序员人生