|
Comments
Did you read today's front page stories & breaking news?
SYS-CON.TV
|
Web Services Creating Message-Based Web Services with WebSphere Studio Application Developer, Part 2
Creating Message-Based Web Services with WebSphere Studio Application Developer, Part 2
By: Greg Flurry
Sep. 25, 2002 12:00 AM
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
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 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
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 two-second delay in the Web service is now reflected in the receive() method. This is exactly the asynchronous behavior desired.
Summary
References
Reader Feedback: Page 1 of 1
Latest Cloud Developer Stories
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week
Breaking Cloud Computing News
|
|||||||||||||||||||||||||||||||||||||||||||||||||