Adding a Web Service Operation
See Also
After you create a web service, you implement its operations in the implementation class. You can add operations
manually in the Source Editor or by using the Add Operation dialog box. In the latter case, the IDE automatically
declares the operation in the Service Endpoint Interface (the "interface"), if there is one (it is optional in the
JAX-WS programming model) and adds a skeleton method in the implementation class.
- You can also add operations to a web service created from a WSDL file.
In this case, you can specify the XML schema types as parameters and return types.
To add a web service operation:
- Open the Add Operation dialog box in one of two ways from the Projects window:
- Expand the Web Services node, right-click the web service
instance node, and choose Add Operation.
- Expand the Source Packages node, expand the package that
contains the web service, and double-click the web service's
implementation class so that it opens in the Source Editor.
Right-click anywhere in the body of a class and choose
Web Service > Add Operation.
This command is only enabled when you click within the body of the class (after the class declaration).
- Define the name, return type, parameters, and exceptions of the web service
operation. For example, do the following if you want to create this operation:
public int add(int a, int b) throws MyException {
return a + b;
}
- Type add in the Name text box
and choose int from the Return Type drop-down.
- Click Add.
- Choose int from the Type drop-down
and type a in the Name text box. Click OK.
- Click Add.
- Choose int from the Type drop-down
and type b in the Name text box. Click OK.
It is not necessary to add the java.rmi.RemoteException exception, because
the IDE does this for you.
- Click OK to create the operation.
The IDE adds the skeleton of the operation to the implementation class and
declares it in the interface.
- In the Source Editor, implement the web service operation. For
example, for JAX-RPC you could add
return a + b; between the braces. Do this in the implementation class, not
in the interface. For JAX-RPC, if your web service is named CalculatorWS, the implementation class
is named CalculatorWSImpl or CalculatorWSBean and the interface is named CalculatorWSSEI.
- See Also
- About Web Services
- About Implementing Web Services
- Creating a Web Service from Java
- Creating a Web Service from a WSDL File
Legal Notices