Thursday, August 21, 2014

Java SOAP Web Service (1)

What is a SOAP Web Service?
SOAP stands for Simple Object Access Protocol. This protocol allows a service to be running on a remote machine and accessed not only from another computer but from different languages as well. For example you can write a Java Web Service and someone else can be writing a C++ application that uses your service.

How is this possible?
There is no good way to go straight from a POJO (Plain Old Java Object) to a C++ object, so what happens is the web service and the client have a common component called the SEI (Service Endpoint Interface) and this SEI is responsible for converting the POJO to a generic type and the client SEI is responsible for converting from the generic type to C++ (in this example). The generic protocol I am referring to is XML!

How do I make a SEI?
Easy! The SEI can be auto-generated for you by using the WSDL for the web service. After setting up JavaEE SDK you will have a tool available to you called 'wsimport' from command line that will allow you to generate the SEI automatically.

  1. Open your Terminal or Command Line
  2. Type 'wsimport -keep -d <directory to put files> <WSDL URL>
  3. Now you can copy the .java files in this case into your Eclipse project and call their methods defined by the Web Service
How to create a WSDL?
The WSDL or Web Service Description Language is commonly referred to as the 'contract' and it contains all of the type information, method calls, and objects template for the web service.
As the developer of the Service you have it pretty easy:

  • import javax.jws.WebService;
  • Add @WebService to the class or interface
    • Optional: Add arguments to the annotation
    • Optional: Mark methods with @WebMethod annotation (public methods will be publish by default)
  • Publish it to Glassfish

If you have any further questions about what a SOAP Web Service is ask in the comments section.
For instructions on how to install JavaEE SDK and configure Glassfish Server see my related blog post.



No comments:

Post a Comment