網路上 step by step 的文章已經很多了,這邊僅記錄我在 Eclipse + JBoss7 上產生 Client 遇到的問題。不定期更新(如果我還持續踩到雷的話)。
不支援 static array
編輯 WSDL 時,Eclipse 會回報以下錯誤。Multiple annotations found at this line:
- WS-I: (BP2108) An Array declaration uses - restricts or extends - the soapenc:Array type, or the
wsdl:arrayType attribute is used in the type declaration.
- WS-I: (BP2102) An XML schema import element references something other than an XML
schema definition: the referenced element does not have "schema" from XML namespace "http://
www.w3.org/2001/XMLSchema" as root element.
修改 WSDL ,改為 dynamic array style。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- static array style --> | |
<xsd:complextype name="__messages"> | |
<xsd:sequence> | |
<xsd:element name="message" type="tns:ArrayOf__message" minoccurs="0" /> | |
</xsd:sequence> | |
</xsd:complextype> | |
<xsd:complextype name="ArrayOf__message"> | |
<xsd:complexcontent> | |
<xsd:restriction base="SOAP_ENC:Array"> | |
<xsd:attribute ref="SOAP_ENC:arrayType" wsdl:arraytype="tns:__message[]" /> | |
</xsd:restriction> | |
</xsd:complexcontent> | |
</xsd:complextype> | |
<!-- dynamic array style --> | |
<xsd:complextype name="__messages"> | |
<xsd:sequence> | |
<xsd:element name="message" type="tns:__message" minoccurs="0" maxoccurs="unbounded" /> | |
</xsd:sequence> | |
</xsd:complextype> |
參考:
不支援 RPC / Encoded
編輯 WSDL 時,Eclipse 會回報以下錯誤。WS-I: (BP2406) The use attribute of a soapbind:body, soapbind:fault, soapbind:header and soapbind:headerfault does not have value of "literal".
修改 WSDL ,將 encoded 改為 literal。雖然這樣修改能順利產生 Web Service Client 的程式碼,但最終還是要看 Web Service 的 Server 端能不能接受 literal 的 SOAP。
<soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace=http://foo/bar use="encoded"/>
<soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace=http://foo/bar use="literal"/>
Eclipse 執行完成卻沒有產生任何程式碼
沒有產生程式碼,沒有任何報錯。用 console 模式來產生程式碼,以 JBoss 7 為例,直接使用 ${jboss_home}/bin/wsconsume.bat 來產生程式碼,錯誤就能正確顯示。
參考: