|
Comments
|
Today's Top SOA Links
Web Services Creating Message-Based Web Services with WebSphere Studio Application Developer: Part 1
Creating Message-Based Web Services with WebSphere Studio Application Developer: Part 1
By: Greg Flurry
Aug. 21, 2002 12:00 AM
WebSphere Studio Application Developer (WSAD) includes support for developing SOAP-based Web services. For example, the WSAD Web Services wizard allows you to turn a JavaBean into a SOAP RPC-based Web service with almost no work. In addition, WSAD can create a proxy for the RPC-based Web service, greatly simplifying its use. Some applications and ser-vices, such as UDDI, require the lower level of control offered by the SOAP message-based model, upon which the RPC-based model is built. Although WSAD doesn't yet provide automated support for SOAP message-based Web services, it's relatively easy to provide manual support in WSAD. This article shows you how to create and use message-based Web services in WSAD. There are three steps to creating a message-based Web service in WSAD:
1. Create an RPC-based Web service to automatically create
artifacts necessary for describing and deploying the Web service.
Creating a SOAP RPC
Web Service
package message; Expand the Web project that contains the MessageService class, select the class, right click, and select New->Other. On the left side of the resulting dialog, select Web Service on the right side and then select Next to start the Web Services wizard. In the initial panel of the wizard (see Figure 1), uncheck Generate Proxy, uncheck Start Web Service, and then select Finish. The wizard creates the WSDL describing the RPC-based Web service as well as a deployment descriptor. The wizard will also start the application server in which the Web service is deployed.
SOAP Message-Based
Web Services
public class <SOAPMessageService> { Modify the signature of the MessageService class and add the functional part of the Web service that implements the message-based Web service. Listing 1 shows the new Web service implementation. The process() method first gets the body from the SOAP envelope received. The method extracts the request element from the body. At this point in a real service, the class would process the request element, execute the business logic required by the request, and formulate a response (in the form of a DOM Element). This simple example just returns the request. Next, modify the Web service deployment descriptor (dds.xml) produced by the Web Services wizard. The dds.xml file can be found in the webApplication folder of the Web project containing the Web service. Simply add the attribute type="message" to the <isd:service> element in the deployment descriptor as shown in Listing 2. After saving the modified deployment descriptor, restart the application server to deploy the Web service and make it available to clients.
Creating a SOAP Message Client Proxy
The send() method sends the request, in this case in the form
of a DOM Element, to the Web service. The send() method uses the
createBody() method to wrap the request in a body element with the
correct name ("process") and namespace attribute. The "xmlns"
attribute identifies the Web service on the server; it should be set
equal to the "id" attribute in the
This generic proxy is useful for sending and receiving
"free-form" documents because it accepts and returns a DOM Element.
It's possible to construct a proxy with a send() method that takes
one or more parameters of a specific Java type, e.g., a String, int,
etc. Likewise, it's possible to have the receive() method return a
specific Java type. A proxy constructed in this fashion must
construct the DOM Element sent to the service and parse the DOM
Element received from the service.
Creating a SOAP
Message Client
Since the proxy requires an element as input, the client
first creates a simple element named "test" with one attribute named
"myAtt". The client then sets the URL for the service implementation;
the value should be set to the value of the location attribute of the
<service/ port/soap:address> element in the "service" WSDL file
generated by WSAD, except that you must substitute "messagerouter"
for the "rpcrouter" in the attribute value. The client then sends the
request to the service. Since the proxy for the message Web service
models an asynchronous operation, the client can now do other things
before retrieving the reply. Eventually, the client receives the
response from the Web service. This example simply prints the
attribute, which should match the attribute in the request. When you
run the test client shown in Listing 4, you'll get the following
result in the WSAD Console view:
The web service echoed the attribute; the value is "good"
This is exactly what's expected.
Digging Deeper
Listing 5 shows the request sent by the client proxy. You can
see that the body of the request contains the <process> element,
which in turn contains the <test> element with its attribute.
Listing 6 shows the response sent as a result of the send()
method. The response contains the <test> element with its attribute.
You may be surprised to find that the response comes back as a result
of the send() method. You can confirm this by putting a breakpoint in
the test client before calling the receive() method and running the
test client in debug mode.
Summary
One final note: the intentional split of the send() and
receive() methods in the proxy allows a
client using the proxy to model asynchronous operations where the
send() method starts the Web service, but does not wait for it to
finish; instead, the receive() method actually waits for the Web
service to finish. In reality, the Web service is synchronous because
the Apache SOAP Message.send() method invoked in the proxy is
synchronous, so the repsonse actually comes back as a result of the
proxy send() method. This means that this client can't operate in an
asynchronous manner; it can't do anything until the proxy send()
method returns. To really be asynchronous, the proxy must implement
some multithreading, which I'll cover in Part 2.
References
Reader Feedback: Page 1 of 1
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 |
|||||||||||||||||||||||||||