WARNING:This tutorial is being written! Do not hesitate to report any errors or suggestions..
The implementation of a Web service, through the Ellipse framework, is extremely simple. If you have questions about what is a Web service, i
refers you to the chapter on the presentation of the basics concepts related to the Web services. For the
implementation and the deployment of a web service, you simply have to follow the next points.
-
Start by checking the configuration of your Web application (file
WEB-INF/web.xml) to accept the proposed extension
for the Web services ( .ws ): this is done in the lines 19 to 22.
01 <?xml version='1.0' encoding='UTF-8'?>
02 <!DOCTYPE web-app PUBLIC
03 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
04 "http://java.sun.com/dtd/web-app_2_3.dtd">
05 <web-app>
06
07 <!-- Begin of file -->
08
09 <servlet>
10 <servlet-name>Ellipse Servlet</servlet-name>
11 <servlet-class>corelib.services.web.webapplications.ControllerServlet</servlet-class>
12 </servlet>
13
14 <servlet-mapping>
15 <servlet-name>Ellipse Servlet</servlet-name>
16 <url-pattern>*.wp</url-pattern>
17 </servlet-mapping>
18
19 <servlet-mapping>
20 <servlet-name>Ellipse Servlet</servlet-name>
21 <url-pattern>*.ws</url-pattern>
22 </servlet-mapping>
23
24 <!-- End of file -->
25
26 </web-app>
File "WEB-INF/web.xml"
-
Encode your Web service by respecting the API JAX-WS (provided by the Java SE 6.0). The following example provides a Web method called
add:
it will allows to add the two values passed as parameters. The two annotations @WebService and @WebMethod are part
of the API JAX-WS and allow to specify what are the classes of Web services and what are the methods accessible through the
network.
01 package corelib.services.web.samples.virtualcaddy.webservices;
02
03 import javax.jws.WebMethod;
04 import javax.jws.WebService;
05
06 @WebService(serviceName = "AddService", name = "Add") public class AddImpl {
07
08 @WebMethod public int add( int a, int b ) {
09 return a + b;
10 }
11
12 }
Class "corelib.services.web.samples.virtualcaddy.webservices.AddImpl"
-
The next step consists to define a file (with a certain point of view, equivalent to a Web page) wich will consists to define the Internet address
of attack of the Web service. It is recommended that this file has the extension
.ws.
01 <?xml version="1.0" encoding="ISO-8859-1" ?>
02 <web:Service xmlns:web="corelib.services.web.webservices"
03 codeBehind="corelib.services.web.samples.virtualcaddy.webservices.AddImpl" />
File "Add.ws"
-
Deploy your Web application in your server (Tomcat or otherwise).
-
Test the proper deployment of Web service by invoking a URL like:
http://localhost:8080/theAppName/Add.ws?wsdl. If everything is
well, the WSDL (Web Service Description Language) should be returned to you. Now, you just have to code a client.