Java開(kāi)發(fā)WebServices傳遞pojo提示參數(shù)不匹配的問(wèn)題
來(lái)源:程序員人生 發(fā)布時(shí)間:2015-01-28 08:52:54 閱讀次數(shù):2906次
webservices服務(wù)用Java開(kāi)發(fā)的時(shí)候,參數(shù)為基本數(shù)據(jù)類(lèi)型是沒(méi)有甚么問(wèn)題的。
但是如果是傳遞pojo,也就是java對(duì)象,可能你會(huì)遇到參數(shù)不匹配的問(wèn)題。
webservices接口暴露出來(lái)以后肯定是1個(gè)wsdl文件,看到網(wǎng)上很多文章說(shuō)“webservices傳遞pojo的時(shí)候,提示參數(shù)不匹配,很多人解決方式是把接口和pojo放在1起就好用了。這個(gè)實(shí)際上是表象”
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>
以上是我開(kāi)發(fā)的1個(gè)webservices接口對(duì)應(yīng)的wsdl文件, 文件中我的targetNamespace是
targetNamespace="http://d.c.b.a/"

也就是說(shuō) 我的webservices服務(wù)真?zhèn)€person和targetNamespace不是1樣的路徑。
------------------------------------------------------------------------------------------------------------------------
我們?cè)賮?lái)開(kāi)發(fā)1個(gè)客戶(hù)端程序。

客戶(hù)真?zhèn)€person路徑為服務(wù)端targetNamespace是對(duì)應(yīng)關(guān)系。
這類(lèi)情況下,傳遞pojo才能調(diào)通。
總結(jié):webservices服務(wù)真?zhèn)€pojo路徑無(wú)所謂在這里,只要客戶(hù)端pojo包路徑和wsdl文件中targetNamespace對(duì)應(yīng),就能夠調(diào)用通過(guò)。
網(wǎng)上說(shuō):客戶(hù)端必須把pojo和接口聲明放在1起的結(jié)論實(shí)際上是不對(duì)的。
生活不易,碼農(nóng)辛苦
如果您覺(jué)得本網(wǎng)站對(duì)您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈(zèng)