Introduction to Web Services
As part of our series on Web 2.0 we turn our attention to data management. Web Services are a way to allow an enterprise to give access to their internal data in a platform agnostic way.
What is unique about web services is that the requests are made across the Internet the same way you would make a request using your web browser – using the HyperText Transfer Protocol (HTTP). This means that an existing infrastructure can be used to set up a web service and make it instantly accessible to the world.
Another significant feature of Web Services is that they use XML to communicate. This creates a generic and well-defined way of passing information. Since XML is the Extensible Markup Language, you can format your message in any way you like. XML just provides the syntax, not the semantics of your message. To define the message further you need a Web Service Definition Language file or WSDL. The WSDL is both in XML and available from the web service as well. Putting your WSDL on line “publishes” the web service for all to see and use.
It isn’t enough to publish the web service and pass XML over HTTP, you need some sort of wrapper to encapsulate the message. The XML is wrapped with a SOAP message (in XML again) that gives some details about the message itself.
The real value of all of this is that it is operating system and language agnostic (Although in this article we’ll look mostly at Java). A web service can be written in .NET and consumed by a client written in Java. Since all the communication between the two parties is in XML, there is no need to translate from one format to another.
All of this does not come without a fee. XML must eventually be consumed and translated into a form that the consumer can understand. This “marshalling” and “unmarshalling” of XML to and from native tongue can take as much as 25% of the processing time of an application; a pretty hefty price to pay for system agnostic messaging.
Creating client code is non-trivial and there are many code generators which will do it for you. BEA’s WebLogic will create a client from a WSDL as well IBM’s WebSphere. Both create clients that require proprietary libraries to work. It is therefore best to use an open source solution that will allow you to migrate your client from one system to another without much work.
One such open source solution is Axis from the Apache Foundation (http://ws.apache.org/axis/). It includes a code generator that uses Axis proprietary libraries. This is a reasonable trade-off. While you may be locked-in to Axis when you use their WSDL2JAVA, it is free for the taking so you can migrate to other platforms easily.
On the other side of the equation, BEA, IBM, and Axis allow you to create a skeleton web service from either a WSDL or a Java file. This allows you to create a Plain Old Java Object (POJO) with the methods to call (and their parameter list) and a WSDL and web service is created for you.
The biggest challenge with using Web Services is that you have to marshall and unmarshall the XML into something readable. The code generators take advantage of one of the existing XML models and convert the XML into Java objects for you. So, from the perspective of the calling program, you are calling the remote service in your native tongue and getting back objects, also in your native tongue. You are virtually unscathed by the details of the web service interface.
Compared to J2EE technologies, Web Services are easier to use. The interfaces for the web service are available to the world – you just go to the URL of the webservice and the information is there. (eg: http://services.xmethods.net/soap/urn:xmethods-delayed-quotes.wsdl).
If you want to talk to an Enterprise Java Bean (EJB) you have to find the interfaces either in code or in a document. Creating the EJB requires a lot of esoteric code that nobody ever sees. Home and Remote interfaces, and so on. Then, once implemented, only other Java applications can take advantage of the service. EJB’s are therefore best used in a monolithic environment where only Java is spoken.
While Web Services are normally used for outward facing services, they are gaining momentum inside the enterprise as well. Their simple-to-use interface and self-documenting nature make web services an easy win within the enterprise. An emerging trend is to create an Enterprise Service Bus that offers cross-cutting concerns such as security, auditing, logging, data translation, and routing. BEA and IBM both offer full ESB products, but BEA has an advantage with their Aqualogic offering.
Web Services are a simple to use method of offering data services to the web. Using existing protocols and standards, a web service can allow an enterprises to give access to its data in a platform agnostic way.
Author: Greg Smith