WebServices : bare vs wrapped?
Asked Answered
S

4

21

I generate some WebServices out of some existing wsdl

I use Maven to do this but some webservices are generated with

@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)  

and the others with

@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.WRAPPED) 

Jaxb or xjc does this automatically ? because i do not have any differences in the wsdls...

Sylviasylviculture answered 16/3, 2011 at 10:34 Comment(2)
Could you post your wsdl file?Whore
XJC doesn't do this, this is the job of the wsimport tool.Boyette
B
29

BARE webservices are generated when the 'operation' name, the 'message' name and the 'element' name are different in some shape or form. To auto generate your client or service stubs as WRAPPED, all of those three elements must be the same.

The workaround to that is to write your own stubs and use the @RequestWrapper/@ResponseWrapper annotations.

PS: All of the portType operations must have a 'wrapped' style request/response. Even the slightest deviation and it will default to BARE.

Bootle answered 25/5, 2011 at 3:47 Comment(2)
Is there an official documentation that explains that further ? A specification document may be ?Knudson
The JAX-WS 2.1 specification explains this in Section 2.3.1.2 ("Wrapper Style")Reareace
A
20

This discussion at Java Ranch Forum cleared it for me. Specifically this example made by Jason Irwin:

BARE client generated interface (using wsimport):

@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)  
public interface IMathServer {  
    @WebMethod  
    @WebResult(name = "addNumsResponse")  
    public AddNumsResponse addNums(@WebParam(name = "addNums") AddNums parameters);  
}  

WRAPPED client generated interface (using wsimport):

@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)  
public interface IMathServer {  
    @WebMethod  
    @WebResult(name = "addNumsResponse")  
    public int addNums(@WebParam(name = "num1") int num1, @WebParam(name = "num2") int num2);  
}  

This both pieces of code generate the same message:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">  
    <S:Body>  
        <ns2:addNums xmlns:ns2="http://SoapStyles/">  
            <num1>1</num1>  
            <num2>2</num2>  
        </ns2:addNums>  
    </S:Body>  
</S:Envelope>  

As said by R Srini in the same discussion what is wrapped are the parameters, not the code.

The only difference generating the clients is the way you are going to create the params in the client, but they both are going to generate the same message (wrapped or unwrapped) depending on the service WSDL.

With BARE you will have only a top element (parameter) with "sub-parameters" inside. This one BARE will be sent directly (without "wrapping" it). While with WRAPPED you will have all this "sub-parameters" in the first level, and the client automatically wrap them in another top element.

Quoting Jason Irwin:

Only one parameter was passed ("addNums") and it was "Bare" in the body. In the second, the parameters were "bare" in the code, but "wrapped" at run-time by JAX-WS.

Hope this helps!

Ashby answered 20/8, 2013 at 20:11 Comment(0)
D
2

Specifies how the method parameters, which correspond to message parts in a WSDL contract, are placed into the SOAP message body. A parameter style of BARE means that each parameter is placed into the message body as a child element of the message root. A parameter style of WRAPPED means that all of the input parameters are wrapped into a single element on a request message and that all of the output parameters are wrapped into a single element in the response message. If you set the style to RPC you must use the WRAPPED parameter style.

Ref http://cxf.apache.org/docs/developing-a-service.html

Deidradeidre answered 29/7, 2013 at 6:41 Comment(0)
H
0

As the name suggests “ParameterStyle” change the syntax of passing and getting the parameters in a method call. And it makes a difference on client side's artifacts generated by wsimport, without making any difference at published service and payloads exchanged between clients/service. If you use BARE with wsimport then the following code would be generated;

public int add(int num1, int num2)

But if you use WRAPPED with wsimport then;

public void add(int num1, int num2, Holder result)

is generated. And this is adopted from the earlier DCE/RPC days.

Herrle answered 16/3, 2011 at 10:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.