Exposing Web services

How can Web services  be used by different services within and outside the application.Web service helps to layer a transport mechanism between any application to any system outside the system. This article provides a view of how web services be used by different services within and outside the application.

The crucial part of a Web service  to define the programming model artifacts that makes the Web service portable with the other application is the port component.  Using within the application may not be what Web services are intended for as this can be achieved through other means as well. Let us explore the model included in the web service.

The programming model includes:

  • A WSDL definition provides the description of a Web service.
  • The service endpoint interface (SEI) defines the operations of the Web service.
  • A service implementation bean implements the SEI methods to provide the business logic of the Web service. The security role references provide instance-level security checks across different modules.
From a server programming model perspective, there are primarily two types of J2EE application artifacts exposed as Web services (service provider):
  • Stateless session EJB(EJB container)
  • JAX-RPC servlet-based service that invokes a Java Bean, known as a service endpoint (Web container)
There are three principal approaches to generating a Web service, depending on the elements that are used to start the creation of the service:
An existing application is used to generate the Web service, which includes a service wrapper used to expose application functionality. This is known as the bottom-up approach.
An existing service definition WSDL is used to generate a new application for a specific programming language and model. This is known as the top-down approach.
An existing group of already generated Web services provides a new combination of functionality (multiple services). Composing a new Web service in this way might include the use of workflow technologies.

Invoking Web services

The J2EE client container provides the WSEE run time used by a Web services client application, to access and invoke Web service methods. The J2EE client container is responsible for the JNDI name to service implementation mapping.
From a client application programming perspective, there are three mechanisms used to invoke a Web service (service consumer) from the Web service client application:
  • A static stub is created before being deployed to the runtime environment.This requires complete knowledge of the WSDL.
  • A dynamic proxy class is created during run time. Only a partial WSDL definition is required (port type and bindings).
  • A dynamic invocation interface does not require WSDL knowledge. The signature or service name is unknown until run time.
The task to build or generate a Web service client (service consumer) depends on the methods of how the client is binding to a Web service server. The client uses a local service stub or proxy to access the remote server and service. The WSDL document is used to generate or set up the particular stub or proxy. The stub or proxy knows at request time how to invoke the Web service based on the binding information.