It's not a secret anymore!*
The moose likes Web Services Certification (SCDJWS/OCEJWSD) and the fly likes Transaction in Webservices Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Services Certification (SCDJWS/OCEJWSD)
Bookmark "Transaction in Webservices" Watch "Transaction in Webservices" New topic
Author

Transaction in Webservices

nitin pokhriyal
Ranch Hand

Joined: May 19, 2005
Posts: 263
I have a question in mind. If there is web service "A" which calls WEb service "B","c" and "D" in a transaction. If "D" fails then how to rollback "B" and "C" transaction. Do we have to make another call to rollback those changes.

Thanks
Nitin
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
There are some alternatives regarding how to handle situations like the one you describe:
1. Design to avoid transactions.
By far the best choice, since it retains the scalability of your web services.
2. WS-Transaction
http://en.wikipedia.org/wiki/WS-Transaction
3. This is not one option, per se, but a couple of design patterns that can be used:
Compensating Service Transaction
Atomic Service Transaction
Best wishes!


My free books and tutorials: http://www.slideshare.net/krizsan
nitin pokhriyal
Ranch Hand

Joined: May 19, 2005
Posts: 263
Ivan thanks a lot for your reply. Looking design pattern i got few question

Atomic Service Transaction :

Q1: In description it is mentioned that Service A and SErvice B start local transaction and save state temporarily. So all services are running under user's parent trnasaction? how service a and service b transaction aware of SErvice c transaction? Only service which is invoking SErvice a, b and c knows it. I think it looks more of TWO-Phase commit.

Compensating Service Transaction :
I did not got this. It has very short description. I will google it more..
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
nitin pokhriyal wrote:Compensating Service Transaction :
I did not got this. It has very short description. I will google it more..

With this design pattern, you replace the transaction with undo-capabilities.
Example:
Web service A uses web service B, C and D to implement an operation.
Each operation in the services B, C and D has a corresponding undo operation that reverses the effect of the corresponding operation by undoing its result on, for instance, the database.
When service A is to perform the operation foo, it calls operation bar on service B , operation czar on service C and operation do on service D in that order.
If an error occurs when calling service D, then service A does the following in an attempt to restore having been interrupted in the middle of carrying out foo:
- Calls operation undoCzar on service C, to reverse the effect of the czar operation having been performed earlier.
- Calls operation undoBar on service B, for the same reason.
- Undoes any resource operations the service A have performed itself.
- Exits the operation and informs the client that an error occurred.

By using the above design pattern, it is possible to avoid locking of resources over long periods of time (in the case when one or more of the operations are long-running) and increase the scalability of involved services.
As an alternative, the undo-capabilities of the services B, C and D can be implemented in service A.
Of course the above design may not be as effective as using transactions and there are situations where it is not suitable or applicable.

Finally, I want to say that I did not come up with this idea myself. If you want more information, I can recommend the book "SOA Design Patterns" by Thomas Erl.
I hope I will have time to answer the other part of your question tomorrow.
Best wishes!
nitin pokhriyal
Ranch Hand

Joined: May 19, 2005
Posts: 263
Thanks Ivan, you cleared my doubts i had similar example in my mind about undoing but all pieces were scattered you made it clear.

I can brief you example like this.

Customer "A" places order on a "DELL" website. then "DELL" makes futher call to vendor for e.g. "Network card", "Graphics card",etc" then they will process order
and finally customer gets his order.



Thanks once again.
Nitin
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
nitin pokhriyal wrote:Customer "A" places order on a "LLED" website. then "LLED" makes futher call to vendor for e.g. "Network card", "Graphics card",etc" then they will process order
and finally customer gets his order.

Good example - it makes it even easier to understand!
Lets say the customer wants a complete computer or nothing at all. If the LLED web service successfully orders a network card, a graphics card, but not a harddrive, then the LLED web service can cancel the orders (undo) for the network and graphics card.

LLED is a new, exciting, computer manufacturer.
Best wishes!
nitin pokhriyal
Ranch Hand

Joined: May 19, 2005
Posts: 263
Thank.. So during undo there has to be some common Id. It can be Transaction Id which is common to all the webservices to undo. is this assumption ok?
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
No, there does not have to be any common id, as far as I understand.
If the LLED web service successfully orders, for instance, a network card, then it receives an order id as a result of the successful operation. Such an order id may later be used to cancel the order (undo the ordering operation). The order ids of the different parts of the computer are, most likely, different.
Best wishes!
nitin pokhriyal
Ranch Hand

Joined: May 19, 2005
Posts: 263
I didn't mean specifically TransactionId but some sort of identification which is recognized by all to cancel order. I think orderId makes more sense.

Thanks for your time in replying queries.

Thanks once again.
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
I almost forgot to say something about Atomic Service Transactions.
As far as I can understand, this looks more like the traditional transaction scenario that you may see with, for instance, EJBs.
In your example with the LLED computer shopping service, the first service (the one being responsible for ordering the components) starts a transaction in which each of the component ordering services also run. If one of the component ordering services fails, then the entire transaction is rolled back, including any component orders. If all the component ordering services succeed, then the transaction is committed and all the components ordered.
This could, in the case of web services, be accomplished by using WS-Transaction to propagate transactions over web service calls.
Best wishes!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Transaction in Webservices
 
Similar Threads
BMT and Session beans
Transaction Attribute & Rollback Question
Spring Hibernate Transaction
Weblogic 7.0 certification mock test question
ICE 287 answers for WebSphere 5.0