How to create a sample Web Service using JDeveloper

Thanks to Hussain for creating this tutorial. I am just extending his learning with some additions of mine.

The Sample WebService will return Credit Rating of the customer if the customer Id is Valid else it will give response as Invalid Customer Id

1) Open JDeveloper, Create New Application and Project as shown below

2) Create a Java Class, Right Click on Project->New->General->JavaClass

3) Enter Class Name as CreditRating and Package name as com.ws

4) Write a Method called getCreditRating inside the class CreditRating class.
the method should accept customer id and return a CreditRating of the customer.

package com.ws;
import java.io.Serializable;

public class CreditRating implements Serializable
{
public CreditRating()
{
}
/**
* Do read this link for help
* in case of issues : http://programming.itags.org/development-tools/123309/
* @webmethod
*/
public String getCreditRating(String customerId)
{
String rating;
if("abc".equalsIgnoreCase(customerId) ||
"xyz".equalsIgnoreCase(customerId) )
{
rating="1000";
}
else if("pqr".equalsIgnoreCase(customerId))
{
rating="2000";
}
else
{
rating = "Invalid Customer id";
}
return rating;
}
}

5) Compile your Project, After Successful Compilation, Right Click your Project->Business Tier-> Web Services-> Java Web Service

6)Enter WebService Name and Select the CreditRating Class as Component to Publish and click Next

7) Once You Successfully generate the Java Web Service, You need to deploy it and Test the working of the Web Service
8) Right Click on MyWebService1 and Select Run. You’ll see a URL in the Log window as shown below.

  • You will see a URL in the second last line

    Use that URL to test the webservice.