4

Here is the part of my WSDL. I'm using the code first approach.

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

What annotation should I add or change so to change this

<input message="echoString"/>

to read as

<input message="echoStringRequest"/>

Thanks all.

Ravi
  • 7,939
  • 14
  • 40
  • 43
  • I know its a very old thread.. did you find any solution? Im struggling with this issue now... – kaluva Jun 01 '23 at 15:18

2 Answers2

2

I am quite surprised myself, but after trying for a while I looked into the spec and it seems you cannot really do this in jax-ws (except in a non-standard way, depending on the implementation). Here is what the jax-ws 2.0 specification says on this issue. See Java to WSDL 1.1 Mapping, Section 3.5, page 32:

The value of a wsdl:message element’s name attribute is not significant but by convention it is normally equal to the corresponding operation name for input messages and the operation name concatenated with “Response” for output messages. Naming of fault messages is described in section section 3.7.

So the only option that comes to my mind is to rename your operation, for example by changing or adding a @WebMethod annotation. Here is an example:

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

This will generate the following portType:

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

The decision of whether you are more happy with this version is up to you.

joergl
  • 2,850
  • 4
  • 36
  • 42
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.

Stefan Berger
  • 423
  • 6
  • 11