![](/img/trans.png)
[英]Generating POJO from WSDL with equals/hashCode methods using apache CXF
[英]Error while generating client from wsdl using apache cxf
我嘗試使用cxf(版本2.2.3,2.2.6和2.7.0)通過給出以下命令從wsdl生成存根和客戶端
> wsdl2java.bat -p com.easynet.eordering.client -client http://expediter.staging.gis.easynet.com:7001/cds/services/eordering?wsdl
但我得到一個錯誤
WSDLToJava錯誤:非獨特的身體部位! 在端口中,操作必須在線路上具有唯一的操作信號,以便成功發送。 在端口{http://eordering.uk.easynet.net} eorderingPortSOAP,Operations“{http://eordering.uk.easynet.net} getAMList”和“{http://eordering.uk.easynet.net} getDCList “擁有相同的請求正文塊{http://eordering.uk.easynet.net} userListRequest
我知道為什么拋出這個錯誤,在我的wsdl操作中被寫為
<operation name="getDCList"><input message="tns:userListRequest"/><output message="tns:userListResponse"/></operation>
<operation name="getAMList"><input message="tns:userListRequest"/><output message="tns:userListResponse"/></operation>
我只是為這兩個操作重用了userListRequest參數,我相信錯誤是因為在兩個操作中都指定了相同的參數(userListRequest)。
有沒有辦法在不更改wsdl的情況下避免此錯誤? (據我所知,wsdl 1.2不允許操作重載,但輸入參數重載?)。
這樣的WSDL不符合WSI-BasicProfile。 看到:
http://www.ws-i.org/profiles/basicprofile-1.1.html#Operation_Signatures
該配置文件將操作簽名定義為將顯示在soap:Body中的元素的名稱。 因此,如果兩個操作使用相同的子元素(或您的情況下的消息),則它們被視為非唯一且違反:
R2710 The operations in a wsdl:binding in a DESCRIPTION MUST result in operation signatures that are different from one another.
如問題中所述:
有沒有辦法在不更改wsdl的情況下避免此錯誤?
如果無法修復WSDL,則可以禁用其驗證:
-validate =無
或者如果您使用Maven:
<configuration>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/wsdl/my.wsdl</wsdl>
<validate>none</validate>
</wsdlOption>
</wsdlOptions>
</configuration>
不確定這是否會在運行時導致問題。 我很快就會發現這個並將更新這篇文章。
如果可以使用WSDL更改並使用WS-I Basic Profile 2.0,則可以向元素wsdl:input
(內部元素wsdl:operation
)添加具有唯一值的 wsa:Action
:
例如
<wsdl:operation name="update">
<wsdl:input message="tns:myMessage" wsam:Action="namespace/port/operation" />
</wsdl:operation>
在WS-I Basic Profile 2.0中,“操作簽名”的定義:“配置文件將”操作簽名“定義為WSDL綁定中的操作所描述的SOAP輸入消息的SOAP主體的子元素的完全限定名稱。以及wsa:Action SOAP標頭塊的URI值(如果存在)。“
另一種解決方法是嘗試從WSDL獲取模式文件。 和maven下面的插件生成java類
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>schema1-generate</id>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<extension>true</extension>
<bindingFiles>
<bindingFile>${basedir}/src/main/resources/wsdl/service-bindings.xjc</bindingFile>
</bindingFiles>
<wsdlDirectory>src/main/resources/wsdl</wsdlDirectory>
<wsdlFiles>
<wsdlFile>Service.wsdl</wsdlFile>
</wsdlFiles>
<keep>true</keep>
<sourceDestDir>target/generated-code/src</sourceDestDir>
<vmArgs>
<vmArg>-Djavax.xml.accessExternalSchema=all</vmArg>
</vmArgs>
</configuration>
<phase>generate-sources</phase>
</execution>
</executions>
</plugin>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.