java jax-ws/wsimport 生成带有 void return 的 WebMethod - 相同的 Request/ResponseWrapper
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10169072/
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
jax-ws/wsimport generates WebMethod with void return - same Request/ResponseWrapper
提问by Nicholas Albion
I'm working with a client's WSDL file that uses the same element definition for the input and output messages, but I'm having trouble getting JAX-WS/JAXB to unmarshal the response.
我正在使用客户端的 WSDL 文件,该文件对输入和输出消息使用相同的元素定义,但我无法让 JAX-WS/JAXB 解组响应。
<wsdl:message name="invokeServiceRequest">
<wsdl:part element="impl:requests" name="multiRequestWrapper"/>
</wsdl:message>
<wsdl:message name="invokeServiceResponse">
<wsdl:part element="impl:requests" name="result"/>
</wsdl:message>
<wsdl:portType name="GCGatewayPortType">
<wsdl:operation name="requests">
<wsdl:input message="impl:invokeServiceRequest" name="invokeServiceRequest"/>
<wsdl:output message="impl:invokeServiceResponse" name="invokeServiceResponse"/>
</wsdl:operation>
</wsdl:portType>
For some reason, the code generated by wsimport has a void return, and the INOUT params don't seem to be updated when the response is received.
出于某种原因,wsimport 生成的代码有一个 void 返回值,并且 INOUT 参数在收到响应时似乎没有更新。
/**
* This class was generated by the JAX-WS RI.
* JAX-WS RI 2.1.7-b01-
* Generated source version: 2.1
*/
...
@WebMethod
@RequestWrapper(localName = "requests", targetNamespace = "http://cg.test.com/", className = "com.test.cg.RequestsType")
@ResponseWrapper(localName = "requests", targetNamespace = "http://cg.test.com/", className = "com.test.cg.RequestsType")
public void requests(
@WebParam(name = "paramOne", targetNamespace = "http://cg.test.com/", mode = WebParam.Mode.INOUT)
Holder<String> paramOne,
@WebParam(name = "paramTwo", targetNamespace = "http://cg.test.com/", mode = WebParam.Mode.INOUT)
Holder<String> paramTwo,
@WebParam(name = "requestList", targetNamespace = "http://cg.test.com/", mode = WebParam.Mode.INOUT)
Holder<List<RequestType>> requestList);
When I call port.request( paramOne, paramTwo, requestList )
, I can see that the SOAP request is sent to the server, which responds with a valid SOAP response:
当我调用 时port.request( paramOne, paramTwo, requestList )
,我可以看到 SOAP 请求被发送到服务器,服务器以有效的 SOAP 响应进行响应:
<soapenv:Envelope ...>
<soapenv:Header />
<soapenv:Body>
<requests ...>
<paramOne>1</paramOne>
<paramTwo>2</paramTwo>
<requestList>
<!-- various elements that JAXB has generated code for -->
However, when I run my app in debug mode, I can see each RequestType
instance in the debugger variables view, but because RequestsType
has an <xsd:choice>
with RequestData
or ResponseData
, the latter is null and the RequestData
is as I provided.
但是,当我在调试模式下运行我的应用程序时,我可以RequestType
在调试器变量视图中看到每个实例,但是因为RequestsType
有一个<xsd:choice>
withRequestData
或ResponseData
,后者为空,而RequestData
正如我提供的那样。
I've successfully used JAX-WS on other projects, but in those cases it generated code with a @WebResult
and non-void return type named after the WebResult. In this project, I think I'm not getting the WebResult because JAX-WS has decided that the request and response types are the same and it can reuse the same object - but how do I get it to update that object with data from the response?
我已经成功地在其他项目中使用了 JAX-WS,但在这些情况下,它生成的代码具有@WebResult
以 WebResult 命名的非空返回类型。在这个项目中,我想我没有得到 WebResult 因为 JAX-WS 已经决定请求和响应类型是相同的并且它可以重用相同的对象 - 但是我如何让它用来自回复?
回答by Isaac
You can solve this by instructing JAX-WS to disable wrapping. This is done through a JAX-WS bindings file.
您可以通过指示 JAX-WS 禁用包装来解决此问题。这是通过 JAX-WS 绑定文件完成的。
<jaxws:bindings xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
<jaxws:enableWrapperStyle>false</jaxws:enableWrapperStyle>
</jaxws:bindings>
回答by ZachOfAllTrades
I was having exactly the same problem. I experimented with the names I was using for the various types, elements, message names, operations names, and such. I finally found the key, and something you said in your question actually got me close to the answer:
我遇到了完全相同的问题。我试验了我用于各种类型、元素、消息名称、操作名称等的名称。我终于找到了关键,你在问题中所说的话实际上让我接近了答案:
In this project, I think I'm not getting the WebResult because JAX-WS has decided that the request and response types are the same and it can reuse the same object - but how do I get it to update that object with data from the response?
在这个项目中,我想我没有得到 WebResult 因为 JAX-WS 已经决定请求和响应类型是相同的并且它可以重用相同的对象 - 但是我如何让它用来自回复?
I looked at my wsdl, which was generating similar java code (with void return and a parameter list instead of a single object parameter). But I have different input and output types. What about my wsdl was similar to yours?
我查看了我的 wsdl,它生成了类似的 java 代码(带有 void 返回和参数列表,而不是单个对象参数)。但我有不同的输入和输出类型。我的 wsdl 和你的相似吗?
The name of the operation was the same as the name of the element defined for the input type. I would suggest that you change your operation name from 'requests' to something like 'processRequests', or leave the operation name alone, and change the name of the element used for the message definitions.
操作名称与为输入类型定义的元素名称相同。我建议您将操作名称从 'requests' 更改为类似 'processRequests' 的名称,或者单独保留操作名称,并更改用于消息定义的元素的名称。
<wsdl:operation name="requests">
becomes
变成
<wsdl:operation name="processRequests">
I'd love to hear if this works for you.
我很想知道这是否适合你。