Monday, 29 April 2013

Small Step for Java Web Service,



Java Web Service
Create and Deploy simple Web Service and Web Service Client in Eclipse


Step 1) Install Apache Tomcat (I am using Tomcat 7)
Step 2) Open Eclipse, Create Dynamic web project


(Here I am giving the Name of My Project is  Animal_WebService ” )






Step 3) Create Service Class, Here I am creating “AnimalsData.java” class, which have one method
getAnimalType () method with String parameter.


Step 4) Now, it’s time to create Web service
Right click on “Java Resource” > “New “> “Other”  and Select Web Service


Step 5) Now, We are using Bottom Up  Web service Approach,
Select your Service class, which we have created last. And enable” publish the Web Service” option

Step 6)
After Click to Next” it will ask you for starting the Server. So click the Start Now.



Step 7)
At Last click finish, It will create Automatically “wsdl file of  your Web service.
You can Find It from: Web Content>Wsdl> AnimalsData.wsdl

Now Our Web service is Starting on Localhost:8080
You can Find Your Web service URI from your AnimalsData.wsdl file,

Here in my example My Web service URL is: http://localhost:8080/Animal_WebService/services/AnimalsData

















Use Web service  With Client Application

Step 1) Open Eclipse, Create Simple java Project


Step 2) Open Command Prompt: go to your AnimalData_client Project SRC folder
Fire following command:
 


                        This is The URL of Your Web service


After executing this command , Automatically the Client Stub Classes  (6) will be created,
You can find it in       src/com/arif/animal
Step 3):
Now, come again to Eclipse,
Create Simple CallAnimalData class, to call web service method
Step 4):
Now, Implement AnimalService with
AnimalsDataService service = new AnimalsDataService();

AnimalsData animalInfo = service.getAnimalsData();
Step 5): run this class as run Application,

 You will see, output..
********************************************************
Tiger is Wild
Cat is Domestic
Dove is Bird
Crock is Sorry ,Dont Know!!


Thanks…………………………………