有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

使用apache cxf从wsdl生成客户端时发生java错误

我已经尝试使用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 Error: Non unique body parts! In a port, operations must have unique operation signaure on the wire for successful dispatch. In port {http://eordering.uk.easynet.net}eorderingPortSOAP, Operations "{http://eordering.uk.easynet.net}getAMList" and "{http://eordering.uk.easynet.net}getDCList" have the same request body block {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?(据我所知,WSDL1.2不允许操作重载,但允许输入参数重载?)


共 (4) 个答案

  1. # 1 楼答案

    另一个解决方法是尝试从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>
    
  2. # 2 楼答案

    这样的WSDL不符合WSI基本配置文件。见:

    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.
    
  3. # 3 楼答案

    如果WSDL更改是可能的,并且使用了WS-I基本概要文件2.0,那么您可以将带有unique valuewsa:Action添加到元素wsdl:input(元素wsdl:operation内部):

    例如

    <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值(如果存在)

  4. # 4 楼答案

    如问题所述:

    Is there any way to avoid this error without making changes to the wsdl ?

    如果无法修复WSDL,可以禁用其验证:

    -验证=无

    或者,如果您正在使用Maven:

    <configuration>
        <wsdlOptions>
            <wsdlOption>
                <wsdl>${basedir}/src/main/wsdl/my.wsdl</wsdl>
                <validate>none</validate>
            </wsdlOption>
        </wsdlOptions>
    </configuration>
    

    不确定这是否不会在运行时导致问题。我会很快找到这个,并会更新这篇文章