3

I'm new to webservice and going through the book "Java WebServices Up and Running". Somehow i find this little confusing for the beginners. On page 54, it makes contradictory statements.

First it says

In the unwrapped style, the parameters occur bare; that is, as a sequence of unwrapped XML subelements in the SOAP body. In the wrapped style, the parameters occur as wrapped XML subelements of an XML element with the name of the service operation

And then it says.

What may be surprising is that the structure of the underlying SOAP messages, both the request and the response, remain unchanged. For instance, the request message from the simplified client AmazonClientU is identical in structure to the request message from the complicated client AmazonClientW.

I tried writing a sample program and i clearly see a difference between the SOAP messages of Wrapped Style and Bare style. The Bare style doesn't contain the operation name in the SOAP body.

Someone please clarify. Thanks in advance..

Greg Kopff
  • 15,945
  • 12
  • 55
  • 78
Jack
  • 305
  • 1
  • 3
  • 13
  • Maybe a look to the errata http://oreilly.com/catalog/errata.csp?isbn=9780596521127 can help you, to see if there is a known error in the book. if you know the pagenumber you can find it easily. – burna Jan 01 '13 at 02:47
  • This response helped me: http://stackoverflow.com/a/6119321/1238957. And this post in Java Ranch has a good explanation too: http://www.coderanch.com/t/501314/Web-Services/java/Simple-Unwrapped-Wrapped-SOAP-messages – Christian Vielma Aug 14 '13 at 19:47

3 Answers3

3

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!

Christian Vielma
  • 15,263
  • 12
  • 53
  • 60
1

I did some more testing on the Wrapped and Bare style web services and this is what i found.

In the example given in the book the SOAP message is as follows in both the cases.

<soapenv:Body>
  <ns1:ItemSearch>
    <ns1:AWSAccessKeyId>...</ns1:AWSAccessKeyId>
    <ns1:Request>
      <ns1:Keywords>quantum gravity</ns1:Keywords>
      <ns1:SearchIndex>Books</ns1:SearchIndex>
    </ns1:Request>
  </ns1:ItemSearch>
</soapenv:Body>

In the Wrapped the style, the XML element following SOAP:BODY is the operation name

In the BARE style, the XML element following SOAP:BODY is not the operation name, but the request parameter name. (which happens to be same as operation name.)

Jack
  • 305
  • 1
  • 3
  • 13
0

I interpret this to mean that while the parameters are handled differently in Wrapped or Bare style, the actual content of the request and response are not different. So, the XML that is passed from client to server will be the same, regardless of whether the server handles the XML in the Wrapped style or the Bare style.

Zagrev
  • 2,000
  • 11
  • 8