Wednesday, March 7, 2007

Web Services sample (Top down EJB Web Service) with Rational Application Developer

Creating a web service is as simple as clicking next buttons. Surprised, yes that is true. Follow this step by step approach and at the end you will be master in web services in couple of minutes.

1.Create Web/Java project

a. Create a web / Jave project to hold wsdl and associated xsd(s).

b. Right click on the left panel (Projects panel) and choose
New --> project or New --> other --> web --> Dynamic Web Project or Java --> Java Project



c. Name it as SampleWeb (for web project) or SampleJava (for Java Project) then click on finish which creates project like shown below.




2. Create an ejb Project

a. Ejb project holds the web services end point or lands all web service calls to this project.

b. Right click on the left panel (Projects panel) and choose
New --> Project or New --> Other --> EJB --> EJB Project



c. Name it as SampleEJB and SampleEAR to associate ejb project




d. Remove the client jar file if you do not want to create separate clientjar for ejb project.



e. Clieck on finish
Note: EJB project complains as it does not have any beans. This is funny, just now you have created a new project and it expects a bean. IBM has to come up with some work around to complain when you want to deploy. Ignore this error for now.



3. Copy wsdl and xsd to the web project

4. Generating service

a. Right click on the wsdl then New --> Other




b. Select --> Web Service --> Web Services
Note: If you have not found the option Please select ‘Show All Wizards’ checkbox.




c. Select ‘Top down EJB Web Service’ in ‘Web Service Type’
Click ‘Service Project’ and select SampleEJB/SampleEAR which we have created earlier




d. Create Client project to test web service

Note: On the fly we are creating client which is a Dynamic web project.


e. Click OK and Next

f. Creating Router Project.
Type ‘SampleHttpRouter’ under HTTP router and click on ‘Next’.




g. If server is not started already it complains, so press StartServer.




h. Some times it may complain to overwrite the existing files. Yes, We have to overwrite web.xml file to get an entry to the new stuff. So please choose to overwrite. If you are familiar with all you can edit later.

i. Keep typing next /finish.



j. You can change source code folder. Some people like me love to have JavaSource as source folder.



k. These are the options which you want to test or generate. As I like to test one place for all methods than having different pages.



5. Editing the Impl file

a. In editor window you will see ‘SampleWSDLSOAPImpl file otherwise you can find it in SampleEJB project.

b. Write the code to implement the calculation of our calculator like below

CalculateResponse resp = new CalculateResponse();
resp.setValC(sampleCalculationRequest.getValA()
+ sampleCalculationRequest.getValB());
resp.setName("Addition");

return resp;


c. You should able to see the result.




Now you are master of web service. Keep practicing and good luck.

No comments: