aspose file tools*
The moose likes Web Services and the fly likes RPC vs Document Style Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "RPC vs Document Style" Watch "RPC vs Document Style" New topic
Author

RPC vs Document Style

Kannan Plr
Greenhorn

Joined: Nov 04, 2003
Posts: 4
Hi,

What makes or Why RPC Style Webservice is tightly coupled and Document style webservice is loosely coupled. I fail to find the difference other than the format of the message being exchanged.

SOAP Body of RPC-style Web Service
<SOAP-ENV:Envelope...>   
   <SOAP-ENV:Body>
      <m:GetStockQuote xmlns:m="urn:xmethods:example">
         <Symbol>Foo</Symbol>
      </m:GetStockQuote>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>


SOAP Body of Document-style Web Service
<SOAP-ENV:Envelope ...>   
   <SOAP-ENV:Body>
      <StockQuoteRequest symbol="FOO"/>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>


(Message taken from the link http://www.oracle.com/technology/sample_code/tech/java/j2ee/jintdemo/tutorials/webservices.html ) , how does the difference in the message makes an impact to tightly coupled or loosely coupled ?

Thanks
plrkannan

Yaron Naveh
Greenhorn

Joined: Oct 26, 2008
Posts: 24
I assume they mean that with RPC there are a few constraints on the message structure, e.g. the root element is the operation name and etc. In doc/lit you have more freedom. But I agree the statement in the link is a little vague.


[url]http://webservices20.blogspot.com/[/url]
Web Services Performance, Interoperability And Testing Blog
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
My guess is:
RPC is more tightly coupled, because if you make any changes in the message structure, then you need to change all clients and servers processing that kind of message.
If you use Document style, then you can send an XML document to the web service.
- If you need to add a new attribute or element to the XML document, you can make it optional to preserve compatibility with older clients.
- If you need to dramatically change the document accepted by the service, or add a new document type, you can introduce an XML document in a different namespace. The server can be implemented to inspect the namespace of the payload of an incoming request to determine how the request is to be processed.

However, if you use RPC and have an operation parameter of the type anyType, then you can also accomplish the same for RPC.
Best wishes!
Leonardo Carreira
Ranch Hand

Joined: Apr 07, 2009
Posts: 489

Hi Friends..

I'm wondering about how to make a Document Style in JAX-WS..
i think the Document Style is good for implementation, isn't it?..
i think with RPC its difficult to implemented in the client side, because i've to change it also, if there's any webservice change in the server side..

please correct me if i'm wrong..

Thanks..


Sorry, perhaps my english language isn't too good.. Prepare for SCJP 6, Please God help me.. ☼
References : [Java.Boot] [JavaChamp] [JavaPrepare]
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
@Leonardo
As you say, Document style probably is more flexible, but the effort of implementing the web service and clients may be slightly larger.
The likeliness of change is a factor that one has to consider when choosing whether to use RPC or Document style web services. Personally, I would not use RPC for a service that is likely to change or need to be more flexible.

Web service and web service data design and versioning is a difficult and very interesting area!
Best wishes!
Leonardo Carreira
Ranch Hand

Joined: Apr 07, 2009
Posts: 489

Hi Ivan..

Please tell me how to configure JAX-WS Metro implementation for Document Style..
and How to make a client side of it?..
currently if i use Metro, i use only Port interface to get all the methods that i've created in the server..

Thanks in advance..
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Selecting RPC or Document style is done in the WSDL. See http://www.w3.org/TR/wsdl#_soap:binding for details!
Best wishes!
Leonardo Carreira
Ranch Hand

Joined: Apr 07, 2009
Posts: 489

Hi Ivan..

Thanks Ivan for your reply..
I really appreciate it..
Leonardo Carreira
Ranch Hand

Joined: Apr 07, 2009
Posts: 489

i've tried to implements Document Literal as follows :
assume that my implementation like this :


is this code true for make Document style?..

please correct me if i'm wrong...
Thanks in advance..
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Leonardo Carreira wrote:
please correct me if i'm wrong...

There is no need, because you are correct!
You can verify yourself - deploy the web service and take a look at the generated WSDL!
My apologies not having thought of the Java-first way of configuring a web service to be Document/Literal - my head is too set on WSDL-first.
Best wishes!
Leonardo Carreira
Ranch Hand

Joined: Apr 07, 2009
Posts: 489

Hi Ivan..

Yes, actually i prefer to use approach Java First while make WebService..
Okay, Thanks Ivan for your help..
I appreciate it..
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: RPC vs Document Style