2010年10月11日 星期一

Web Service Create (Axis1)

http://onjava.com/pub/a/onjava/2002/06/05/axis.html?page=1

Creating Web Services with Apache Axis1

05.22.2002

Web services have been a buzzword for a while. A friend used to say "Web services are like high school sex. Everyone is talking about doing it, but hardly anyone is, and those that are probably aren't doing it well." These days, though, Web services are moving to college, so to speak, and lots of people are starting to "do it" more often and better than before. Tools are maturing, and creating and working with Web services isn't all that hard anymore.

IBM has given a lot of code to the Apache group, including SOAP4J, their group of SOAP tools. The Apache SOAP and SOAP4J guys got together and are working on the latest and greatest tool set called Apache AXIS, which features not only better performance, but also some new features that make it trivial to play in this new world. I see the most common actions being "I want to expose this functionality as a Web service," and "I want to access that Web service." Surely it should be very straight-forward to strap on this interface, and you shouldn't have to learn everything there is to know about the underlying platform. This is the same idea as not having to know about the IP and TCP layer when accessing a URL over HTTP. Let's keep it simple, folks.

In this article, I will show two parts of this new system:
  • First, I will show the "easy to deploy" feature that lets you drop a source file into the AXIS Web application and have it become a Web service -- just like that!
  • Then we will use the new WSDL2Java and Java2WSDL tools to see how we can quickly get a WSDL descriptor and access the associated Web service, and then how to easily expose some Java code.
All of the code that is listed (and downloadable) was written for Apache Axis beta1. There are more instructions on running the code at the end of the article.

Deploying Your Code as a Web Service in One Easy Step

The Apache guys realized that it would be really nice to be able to drop some code somewhere and have it become a Web service "just like that." This simplicity is a current trend; Microsoft has it in .NET, and BEA in the WebLogic 7 platform. But just how easy is it to:

  • Deploy a piece of code?
  • Write a client that accesses the Web service?
  • Obtain the WSDL for the deployed Web service?

Working With a Production Web Service

Although it is really easy and convenient to shove our Java code under the Axis directory as a .jws file, that will not be the way you deploy all of your Web services. A lot of the time we want more fine-grained control over the Web service, to tweak it, and to use other more advanced features. Luckily, with other tools, it is still easy for us to work with our code in a more formal manner.

Let's walk through the following process:

  1. We have a piece of code that calculates the Fibonacci sequence for a given iteration.
  2. We want to take the existing code, wrap it up as a Web service, and then deploy it to the Apache Axis system.
  3. Once we have a running service on the server side, we will create Java stubs that allow us to communicate with the service, only requiring the WSDL.

After going through this full process, you will be able to create clients to any Web services (when given the WSDL), and wrap upany code, exposing it as a Web service.

Here are the steps we will walk through:

  1. View: Take a peek at the existing Fibonacci code.
  2. Java2WSDL: Generate the WSDL file for the given Fibonacci interface.
  3. WSDL2Java: Generate the server side wrapper code, and stubs for easy client access.
  4. FibonacciSoapBindingImpl: Fill in wrapper to call the existing Fibonacci code.
  5. Deploy: Deploy the service to Apache Axis.
  6. Client: Write a client that uses the generated stubs, to easily access the Web service.

沒有留言:

張貼留言