Java SOAP“wsimport” - 从文档/文字包装的 WSDL 强制包装绑定?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7032381/
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-30 18:21:05  来源:igfitidea点击:

Java SOAP "wsimport" - force wrapped binding from document/literal wrapped WSDL?

javasoapwsdljax-wswsimport

提问by maerics

The Java 6 JAX-WS "wsimport" utility does a great job of generating a web service skeleton (interface) given a WSDL file but with one personally annoying exception.

Java 6 JAX-WS“wsimport”实用程序在给定 WSDL 文件的情况下生成 Web 服务框架(接口)方面做得很好,但有一个个人讨厌的例外。

When given a WSDL that uses the SOAP Document/literal wrapped style(also described here) it generates a service interface with a "bare" SOAP binding parameter style(with multiple arguments and return values expanded as "holder" objectsin the method signatures) instead of the simple wrapped parameter and return value specified by the WSDL. Other tools, such as Axis2 wsdl2java simply use the wrapper elements as the input parameter and return value instead of automatically "unwrapping" them.

当给定一个使用SOAP 文档/文字包装样式也在这里描述)的 WSDL 时,它会生成一个具有“裸” SOAP 绑定参数样式的服务接口(具有多个参数和返回值在方法签名中扩展为“持有者”对象)而不是由 WSDL 指定的简单包装参数和返回值。其他工具,例如 Axis2 wsdl2java 只是将包装元素用作输入参数和返回值,而不是自动“解开”它们。

Is it possible to tell "wsimport" to keep the SOAP binding parameters as "wrapped" instead of "bare"?

是否可以告诉“wsimport”将 SOAP 绑定参数保持为“包装”而不是“裸”?

回答by beny23

AFAIK, you'd need to specify a custom binding file to disable the wrapper style:

AFAIK,您需要指定一个自定义绑定文件来禁用包装样式:

<bindings
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    wsdlLocation="OperationService.wsdl"
    xmlns="http://java.sun.com/xml/ns/jaxws">
        <!-- Disable default wrapper style -->
        <enableWrapperStyle>false</enableWrapperStyle>
</bindings>

and then invoke wsimport

然后调用 wsimport

$ wsimport -b binding.xml OperationService.wsdl

回答by maerics

The answer from @beny23 is on the right track; however, it turns out that you can embed the JAX-WS binding instructions into the WSDL file itself, which eliminates the need to add the "-b binding.xml" switches to the "wsimport" command:

@beny23 的答案是正确的;然而,事实证明您可以将 JAX-WS 绑定指令嵌入到 WSDL 文件本身中,这消除了将“ -b binding.xml”开关添加到“ wsimport”命令的需要:

<wsdl:portType name="HelloPortType">
  <jaxws:bindings xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
    <jaxws:enableWrapperStyle>false</jaxws:enableWrapperStyle>
  </jaxws:bindings>
  <wsdl:operation name="sayHello">...</wsdl:operation>
</wsdl:portType>