Magazine
 
Quick Review:Ajax
 
Developing Simple Web Service

Step 2: Create a simple Java class: (HelloWorldService.java)

Now we need to create a simple class as a web service. In this web service, we can create different methods to perform different operations. Different clients when consuming this web service can use these operations.

For this, in this example, we have created java file named “HelloWorldService.java”. This file has “HelloWorldService” class and the class has “sayHello()” method. The method takes a single String parameter and simply returns the same String with “Hello” text added as a prefix.

HelloWorldService.java

/**
* The service implementation class
*/
package examples.axis2;
public class HelloWorldService {
public String sayHello(String name) {
return “Hello “+name+” !”;
}
}

Save this file as “HelloWorldService.java” in “examples\axis2” folder and compile it.

Step 3: Creating the service descriptor: (services.xml)

Our next step is to inform the Axis engine about this service. For this we need to create “services.xml” file containing the description of different web services.

services.xml:

<service name=”HelloWorldService”>
<description>
This service is to say hello to the user.
</description>
<parameter name=”ServiceClass”>examples.axis2.HelloWorldService</parameter>
<operation name=”sayHello”>
<messageReceiver class=”org.apache.axis2.rpc.receivers.RPCMessageReceiver” />
</operation>
</service>

Save this file as services.xml in “META-INF” folder.

Information of each service is described in a single <service> element. In this example service name is defined as “HelloWorldService”.

You can take multiple service elements for multiple services i.e. include group of services. All these services are enclosed with in <ServiceGroup> element.

May 2008 | Java Jazz Up | 17
 
previous
index
next
 
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,

30
, 31, 32, 33, 34, 35, 36, 37 Download PDF