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

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

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


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

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>

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


也就是说 我的webservices服务端的person和targetNamespace不是一样的路径。


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


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



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


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


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


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

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值