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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13029088/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 11:13:38  来源:igfitidea点击:

Error while generating client from wsdl using apache cxf

javawsdlcxf

提问by Techie

I have tried to generate stubs and client from a wsdl using cxf(versions 2.2.3, 2.2.6 and 2.7.0) by giving the below command

我尝试通过给出以下命令使用 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

but I am getting an error as

但我收到一个错误

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

WSDLToJava 错误:非唯一的身体部位!在港口中,操作必须在线路上具有唯一的操作信号才能成功调度。在端口 {http://eordering.uk.easynet.net}eorderingPortSOAP,操作“{http://eordering.uk.easynet.net}getAMList”和“{http://eordering.uk.easynet.net}getDCList " 具有相同的请求正文块 {http://eordering.uk.easynet.net}userListRequest

I know why this error was thrown, in my wsdl operations are written as

我知道为什么会抛出这个错误,在我的 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>

I was just reusing the userListRequest parameter for both the operations, I believe the error was thrown as the same parameter(userListRequest) is specified in both the operations.

我只是在两个操作中重用 userListRequest 参数,我相信错误是因为在两个操作中指定了相同的参数(userListRequest)而引发的。

Is there any way to avoid this error without making changes to the wsdl ? (as I know operation overloading is not allowed from wsdl 1.2 but input parameters overloading ? ).

有没有办法在不更改 wsdl 的情况下避免此错误?(据我所知,wsdl 1.2 不允许操作重载,但输入参数重载?)。

回答by Daniel Kulp

Such a WSDL would not be WSI-BasicProfile compliant. See:

这样的 WSDL 将不符合 WSI-BasicProfile。看:

http://www.ws-i.org/profiles/basicprofile-1.1.html#Operation_Signatures

http://www.ws-i.org/profiles/basicprofile-1.1.html#Operation_Signatures

The profile defines the operation signature as the name of the element that would appear in the soap:Body. Thus, if two operations use the same child element (or message in your case), they are considered non-unique and violating:

配置文件将操作签名定义为将出现在soap:Body 中的元素的名称。因此,如果两个操作使用相同的子元素(或您的情况下的消息),则它们被视为非唯一且违反:

R2710 The operations in a wsdl:binding in a DESCRIPTION MUST result in operation signatures that are different from one another.

回答by Constantino Cronemberger

As mentioned in the question:

正如问题中提到的:

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

有没有办法在不更改 wsdl 的情况下避免此错误?

If you can't fix the WSDL, you can disable its validation:

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

-validate=none

-验证=无

or if you are using Maven:

或者如果您使用的是 Maven:

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

Not sure if this is not going to cause problems at runtime. I will find this soon and will update this post.

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

回答by Fenix

If WSDL change is possible and WS-I Basic Profile 2.0 is used, you can add wsa:Actionwith unique valueto element wsdl:input(inside element wsdl:operation):

如果WSDL变化是可能的,WS-I Basic Profile的2.0时,您可以添加wsa:Action独特价值,以元素wsdl:input(内元素wsdl:operation):

E.g.

例如

<wsdl:operation name="update">
  <wsdl:input message="tns:myMessage" wsam:Action="namespace/port/operation" />
</wsdl:operation>

In WS-I Basic Profile 2.0 the definition of "operation signature": "The Profile defines the "operation signature" to be the fully qualified name of the child element of SOAP body of the SOAP input message described by an operation in a WSDL binding and the URI value of the wsa:Action SOAP header block, if present."

在 WS-I 基本概要 2.0 中,“操作签名”的定义:“概要将“操作签名”定义为 WSDL 绑定中的操作描述的 SOAP 输入消息的 SOAP 主体的子元素的完全限定名称以及 wsa:Action SOAP 标头块的 URI 值(如果存在)。”

回答by muniraj saravanan

Another work around is try to get the schema file from the WSDL. and the below plugin in maven to generate the java class

另一种解决方法是尝试从 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>