4

这是我的 WSDL 的一部分。我正在使用代码优先方法。

<portType name="MyWebService">
     <operation name="echoString"/>
         <input message="echoString"/>
         <output message="echoStringResponse"/>
     </operation>
 </portType>

我应该添加或更改什么注释才能更改它

<input message="echoString"/>

读作

<input message="echoStringRequest"/>

谢谢大家。

4

2 回答 2

2

我自己很惊讶,但是在尝试了一段时间后,我查看了规范,似乎你不能在 jax-ws 中真正做到这一点(除非以非标准方式,具体取决于实现)。以下是jax-ws 2.0 规范对此问题的说明。请参阅Java 到 WSDL 1.1 映射,第 3.5 节,第 32 页:

wsdl:message 元素的 name 属性的值并不重要,但按照惯例,它通常等于输入消息的相应操作名称和与输出消息的“响应”连接的操作名称。故障信息的命名在第 3.7 节中描述。

所以我想到的唯一选择是重命名您的操作,例如通过更改或添加@WebMethod注释。这是一个例子:

@WebMethod(operationName = "echoStringRequest")
public String echoString(String echoStringRequest) {
    return echoStringRequest;
}

这将生成以下内容portType

<portType name="MyWebService">
   <operation name="echoStringRequest">
      <input message="tns:echoStringRequest"></input>
      <output message="tns:echoStringRequestResponse"></output>
   </operation>
</portType>

您是否对此版本更满意取决于您自己的决定。

于 2013-02-12T20:22:53.320 回答
0

I've encountered this problem myself recently and stumbled upon this thread multiple times. In our application we have a JAX-WS servlet which must use the format of ...Request and ...Response.

After a few days of searching, I found the solution.

Let's say your echoStringRequest has one String property that should be echoed back in the response.

class EchoMessage {
    private String message;

    //add getter and setter
}

First add this annotation to the web service class:

@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)

Then annotate your web service method like this:

@WebMethod
@WebResult(name = "echoStringResponse")
public EchoMessage echoString (@WebParam(name = "echoStringRequest") EchoMessage inputMessage) {
    ...
}

Without the parameterStyle BARE annotation, JAX-WS would automatically generate messages like this:

<echoString>
    <echoStringRequest>
        ...
    </echoStringRequest>
</echoString>

With the annotation, the outer element does not exist anymore.

The @WebParam and @ReturnType annotations are needed to determine the names of the root elements in the SOAP request and response body.

于 2018-02-17T14:06:54.257 回答