Comments
Patrick Collands wrote: collands (AT) gmail com I'd be very grateful for an invitation. Thank you.
Cloud Expo on Google News

SYS-CON.TV

2009 East
PLATINUM SPONSORS:
IBM
Smarter Business Solutions Through Dynamic Infrastructure
IBM
Smarter Insights: How the CIO Becomes a Hero Again
Microsoft
Windows Azure
GOLD SPONSORS:
Appsense
Why VDI?
CA
Maximizing the Business Value of Virtualization in Enterprise and Cloud Computing Environments
ExactTarget
Messaging in the Cloud - Email, SMS and Voice
Freedom OSS
Stairway to the Cloud
Sun
Sun's Incubation Platform: Helping Startups Serve the Enterprise
POWER PANELS:
Click For 2008 West
Event Webcasts
Creating Message-Based Web Services with WebSphere Studio Application Developer, Part 2
Creating Message-Based Web Services with WebSphere Studio Application Developer, Part 2

Part 1 of this article (WSDJ, Vol.1, issue 7) showed how to create and use SOAP message-based Web services in WebSphere Studio Application Developer (WSAD). The standard behavior of such services is synchronous. Despite the provision for asynchronous operation of the message-based Web service proxy in Part 1, the operation wasn't actually asynchronous. This article shows how to provide for truly asynchronous operation using threads.

Instrumenting the Web Service Client
We'll first instrument the Web service client so we can more easily understand its behavior. Listing 1 shows the Web service modified to introduce a two-second delay between receiving the request and returning the response.

Listing 2 shows the client from Part 1 modified so that the client calculates the time required to execute the proxy's send() and receive() methods. The modified client also prints those times.

If you run the modified client, you'll see something similar to the following results in the Console view:

  • The Web service echoed the attribute; the value is "good"
  • The proxy send invoked - interval 2273
  • The proxy receive invoked - interval 100

    The time for the send() method reflects the two-second delay introduced into the Web service. This is because the SOAP Message.send() method used in the proxy send() method called by the client is synchronous.

    Creating an Asynchronous Message Client Proxy
    To introduce asynchrony, we must introduce a "proxy" thread that makes the synchronous call to the Web service so that the proxy send() method, running in the "client" thread, can operate asynchronously with respect to the Web service. The approach shown in Listing 3 introduces a wrapper for the proxy from Part 1. The wrapper has the same signature as the proxy, so the client doesn't have to change. This approach reuses the proxy from Part 1 unmodified.

    First, we create a class that will be used to synchronize the client and proxy threads. The class shown in Listing 3 implements a rather standard pattern for synchronizing threads, using synchronized get() and put() methods.

    Listing 4 shows the implementation of the proxy thread. It implements methods needed to set the URL for the endpoint of the Web service, set the input to the Web service, and set the synchronizing object. Of course, it also has a run() method, which calls setURL(), send(), and receive() methods in the original proxy (from Part 1) to invoke the Web service and get the response. It then puts the response in the synchronizing object.

    Listing 5 shows the proxy wrapper, which has the same signature as the original proxy in Part 1. The new send() method creates an instance of the synchronizing class and an instance of the new thread object and starts the thread. This causes invocation of the proxy thread's run() method, which in turn calls the Web service. The new receive() method calls the get() method of the synchronizing object to retrieve the response.

    Since the revised proxy has the same signature as the proxy in Part 1, we need to make only a small change in the client to use the new threaded proxy. Simply change "Message ServiceProxy" to "ProxyWrapper" and save the revised client. Now run client. You'll see something similar to the following results in the Console view:

  • The Web service echoed the attribute; the value is "good"
  • The proxy send invoked - interval 300
  • The proxy receive invoked - interval 2404

    The two-second delay in the Web service is now reflected in the receive() method. This is exactly the asynchronous behavior desired.

    Summary
    This article walked you through the steps necessary to introduce asynchrony into SOAP message-based Web services. The solution shown isn't the most complete or efficient - exceptions aren't really handled correctly, and it features reuse of both client code and proxy code from Part 1. However, it's a good start that can be customized.

    References

  • "Creating Web-Based Messages with WebSphere Studio Application Developer - Part 1." WebSphere Developer's Journal. Vol.1, issue 7.
  • Web services zone on IBM developerWorks: www.ibm.com/developerworks/webservices.
    About Greg Flurry
    Greg Flurry is a member of the IBM Software Group Emerging Technologies area. His current responsibilities include introducing web services techologies into the IBM WebSphere product family.

  • In order to post a comment you need to be registered and logged in.

    Register | Sign-in

    Reader Feedback: Page 1 of 1

    Latest Cloud Developer Stories
    CloudBench Applications, Inc. announced its financial results for the three months and nine months ending September 30, 2009. All amounts are stated in Canadian dollars unless otherwise noted. Revenues from BasicGov, the Company's cloud computing solution for local government, gr...
    The new contract is an industry first, with CSC being the first Microsoft partner to lead and win a cloud computing services agreement of this scale. Under terms of the contract, CSC will provide Royal Mail Group's 30,000 employees with access to new IT services using Microsoft's...
    Operates in over 170 countries and is one of the world’s leading providers of communications solutions and services. Richard Tarboton talks for MeettheBoss.TV on his role as Head of Energy & Carbon for BT and what they are doing towards reducing carbon emissions.
    CA is going to put its Agile Planner software on salesforce.com’s Force.com platform in the first half to accelerate development time and give users visibility over their development initiatives to reduce time-to-market. Customers are supposed to be able to accelerate the deploym...
    Despite its uncertain fate Sun soldiers on. Monday it trotted out a cloud-based multiplatform desktop as a service for K-12 and community colleges that can run Windows, the Mac OS, Linux and Solaris applications to nearly any client device, including its own Sun Ray thin clients....
    Subscribe to the World's Most Powerful Newsletters
    Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
    Click to Add our RSS Feeds to the Service of Your Choice:
    Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
    myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
    Publish Your Article! Please send it to editorial(at)sys-con.com!

    Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

    SYS-CON Featured Whitepapers
    ADS BY GOOGLE

    Breaking Cloud Computing News
    CloudBench Applications, Inc. announced its financial results for the three months and nine months e...