java2db

Simple Java Web Service Example using eclipse,glassfish



It is very easy to create and run a java web service by using javax.jws  annotations.In the below java web service example , we used Eclipse IDE and Glassfish server for execution .

 

Java Web Service Example Steps to create and run a java web service example :

Java Web Service Example Step 1:

Create new web project ( Ex: HelloWorldWebService) in eclipse .Create a new java class (Ex :HellowWorldService). The directory structure as follows.

 

 

 

Java Web Service Example Step 2:

Copy the below piece of java code in the HellowWorldService.java file.

It is a normal java file with @webService and @WebMethod  annotations. These are from javax.jws package (No need to add any jar files, it is a inbuilt Java SE package) .

 

 

 Java Web Service Example Step 3:

Deploy the project and run the GlassFish server.Open   Admin Console to view the WSDL file or to test the appliction.

 

Java Web Service Example

 

Java Web Service Example Step 4 :

From the Admin Console , Click Applications menu and select HelloWorldWebService .

 

 

 

 

Java Web Service Example Step 5 :

Click View Endpoint link to get the Service Endpoint Information .

 

From the above screen , we can find the Tester and wsdl links.

 

Java Web Service Example Step 6 :

If you want to see the WSDL file then click on wsdl link , it opens the below window.

 

 

 

Java Web Service Example Step 7 :

Click the wsdl link from the above screen .It opens the wsdl file from the source.The file looks like below.

 

Java Web Service Example

 

 

 Step 8 :

To test the deployed application , click the Tester link from Service Endpoint Information (From step 5). It will open the web Service Tester Links.

 

Java Web Service Example

 

 

 Step 9:

Click the Tester link . It opens all the operations that are available in the service.But in our example , we have only one operation called hellow .

 

Java Web Service Example

 

 

 Step 10 :

Click the hellow (method from our java class) button to test our application.The response should be like below.

 

Java Web Service Example

 

 It is possible to execute a java web service like normal java class without using web or application servers.



Related Posts :
How to create WCF web service in C# .NET ( visual studio 2013 )
How to call java SOAP web service in php ( php web service client )
What is RESTful web service (Introduction to RESTful web services)
How to call a web service from another web service (web service chain)
How to provide security to SOAP web services ( JAX-WS )
How to handle custom exceptions using SOAP faults in web services
How to Create a java web service using bottom up approach
Create a java web service from WSDL (Top down approach) in Eclipse
   [will not be published]



^ <