java2db

How to pass input parameters to a Java Web Service



If any web service operation is looking for an argument/arguments to complete its process then the user need to pass valid input parameters based on its type (Example :String,int).See the below java web service simple example , we used Eclipse IDE and Glassfish server for execution .

 

pass input parameters to a Java Web Service Steps to create and run a java web service example with input parameters:

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.

 

pass input parameters to a Java Web Service

 

 

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) .It has a method Hellow which is taking one String parameter called name .

 

If you want to test the application using SoapUI , the process explained in the below link .

[ Test with SoapUI].

 

 

 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 application.

 

 

pass input parameters to a Java Web Service

 

Java Web Service Example Step 4 :

From the below 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.

Tester : To test the deployed application .

wsdl : To check the WSDL file and its content.

 

 

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.

It is a bottom up approach . Which means , first we created the service with proper annotations (@WebService , @WebMethod)and the server generated the wsdl file using Metro.

 

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.

Note :  To test the application using SoapUI , click the link to view the process [ Test With SoapUI ].

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  with one parameter

 

pass input parameters to a Java Web Service

Enter a value to the text box  beside the hellow button .

 

 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.But it allows only single thread .



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]



^ <