Steps for creating the Server Side Component of WebService using RAD

0 comments



There are few steps that needs to be followed in order to create server side component of web service even if you are using IDE like RAD but they are very simple ones. Let create a simple calculator service exposed as web service.

Step1 : Create the Web Service Implementation class

Create a new Dynamic Web Project named as DemoWebService. Follow the below navigation: File>New >Dynamic Web Project. So the web project will automatically create in the workspace which we were created initially. Here the default target server is WebSphere v6.0.

Step1
Step1


Create a package in Java Resources as demowebservice and create CalculatorService class in that package. This class is the implementation class of the web service provider. All the business logic of the web service will be put in this class.
Step2
Step2



Below are the methods present in CalculatorService class. This is a sample example to test the web service so this particular class contains four arithmetic methods. Each method taking two parameters and returns the corresponding result depends upon the operation.
CalculatorService Web Service SOAP Implementation Class:

Calculator Service
Calculator Service


Now publish the CalculatorService.java file as a web service. Below is the navigation to how to make the class as a web service server component.

1.1. How to make the java class as a web service component

Right click on the class CalculatorService->Go to Web Services -> Click on Create Web Service.


RAD
RAD



After clicking on the Create Web Service following screens will come. The creation of web service in RAD internally uses the web sphere commands such as WSDL2Java, JAVA2wsdl etc to create the web service related xml file and other web service supporting files.

Screen1
Screen1


Screen 1:
This step will ask about the web service type. The Web Service Type contains Java bean Web Service, EJB Web Service, URL Web Service etc .The default Web Service Type in RAD is Java bean Web Service. Don’t change any values in screen 1 and click on Next button to go to the next step to select the web service implementation class.
Screen2
Screen2


Screen 2:

This screen will only ask for the implementation class of the web service. Here our implementation class is present in the package demowebservice. This Bean class contains all the business logic related to web service. The web service implementation class (demowebservice.CalculatorService) will automatically selected. If you want any external implementation class click on Browse Classes to select the file and click on Next button.
Screen3
Screen3


Screen 3:

This screen will confirm the server and J2EE version on which the web service will be deployed. You can change the server & J2EE version by clicking on the Edit button.

The Service Project will contain the current dynamic web project name where the web service is going to create.

The EAR project will contain the EAR name of the current project which contains the entire source code of the web service component. Automatically the Service Project & EAR Project will be selected depending upon the class which you want to make it as a web service. Click on Next to select the SEI (Service Endpoint Interface) for the web service.
Screen4
Screen4


Screen 4:

The above screen 4 will give the service end point interface of the bean class. So in the Service End Point interface text box the appropriate SEI will be displayed as disabled. Then click on Next.
Screen5
Screen4


Screen 5:
This screen will ask for all the configurations before creating the web service. The Web Service URI contains the actual location of the web service where it deployed. The wsdl folder contains the location of the wsdl file. All the methods which are present in the bean implementation class will be displayed in the Methods section with check boxes. The methods can modify by deselecting the checkboxes in Methods section. The default style of the web service in RAD is Document/Literal. Most of the language prefers this type of style in web service. The Security configuration combo box contains the different types of security implementations in web services. The security implementations are XML Digital Signature, XML Encryption etc. Here we are not implementing any security, so don’t change any thing and click on next.
Screen6
Screen6


Screen 6:
This screen will ask for publishing the web service in UDDI. If you want your web service as public then publish through UDDI is necessary. Don’t modify any settings and click on Finish.
Project Explorer
Project Explorer


This Screen Shot is the Project Explorer of DemoWebService Project. After creation of web service the below new files were created in the project.

demowebservice\CalculatorService_SEI.java: This Service End Point interface contains all the methods of bean implementation class (CalculatorService.java) in an abstract way.

WebContent\WEB-INF\wsdl\CalculatorService.wsdl: This is the web service description file which contains web service method input & output parameters return type, document style, service provider end point description etc.
Below are the files which will be created related to web service.
  • CalculatorService_mapping.xml
  • ibm-webservices-bnd.xmi
  • ibm-webservices-ext.xmi
  • webservices.xml
All the files will be created in the WebContent\WEB-INF directory. Below figure is a part of the CalculatorService.wsdl file:

WSDL
WSDL


Each method of the SEI will be put inside an element tag. The input parameters of the method will be put inside a complex type tag (<complexType></ complexType). The type attribute of inner element tag contains the xml equivalent data type of java data type. Similarly a new element tag will be created for each method based upon the method return type. The return type of method will be maintained as a separate element tag with name addition with Response. For ex: for addition method the element name will be additionResponse.
WSDL
WSDL


The above code snippet is the service portion of the wsdl file which contains the server address, Port binding information & service name of the web service.

The service component name will be the <SEI name>+ Service. So here the service end point interface name is CalculatorService + Service. The Service name will be inside the <wsdl:service> tag. The web service deployed address will be in <wsdl:address> tag and the location attribute contains the actual address of the server.

No comments:

Post a Comment

Recent Posts

Popular Posts

© 2011-2019 Web Portal Club