Java開發WebServices傳遞pojo提示參數不匹配的問題,webservicespojo
webservices服務用Java開發的時候,參數為基礎資料型別 (Elementary Data Type)是沒有什麼問題的。
但是如果是傳遞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和介面聲明放在一起的結論其實是不對的。