HOME | J2ME | Struts | AJAX | SOAP | SOA MEDIA STREAMING AXIS |
AXIS STEP BY STEP
Web Services
Axis Introduction
Installations
Hello World
Using Eclipse
POJO Service
POJO Client
AXIOM Service
AXIOM Client

 

 

AXIS Hello World Program

Back | Tutorial Home | Next

Here is the simple Hello World Program. Click here to Download this source code of this example

package demo;

public class HelloWorldService {
    public String getHello(String username) {
    	return "Hello World Mr " + username; 
    }
}

Wow!! This is the simplest it can get. And this is the only java file you need to write.

Now let’s create services.xml

<service name="HelloWorldService" scope="application" 
targetNamespace="http://demo/">
	<description>Hello World Service</description>
	<messageReceivers>
		<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
		class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
	</messageReceivers>
	<schema schemaNamespace="http://demo/xsd"/>
	<parameter name="ServiceClass">demo.HelloWorldService</parameter>
</service>

Above xml defines that

  • Service Class is demo.HelloWorldService
  • The message receiver for the above service is “org.apache.axis2.rpc.receivers.RPCMessageReceiver”. Here we have defined the receiver at service level. Alternatively message receiver can be declared at the method level also. Message Receivers are also called Message Exchange Patterns (MEPs)). We will learn more about message receivers in next few lessons.

Now finally have a look at the ant build file build.xml

Now lets see how the above files need to be arranged to build a service(aar file)

In AXIS2_HOME\samples create a new folder helloworld. Create folders in helloworld folder as shown in the following picture

  • Place HelloWorldService.java in helloworld\src\demo
  • Place services.xml in helloworld\resources\META-INF
  • Place build.xml in helloworld folder

Finnaly execute following command “ant generate.service” in helloworld folder

A new folder “build” is created which has HelloWorldService.aar. This is the service executable.

Place HelloWorldService.aar in the <Tomcat-Home>\webapps\axis2\WEB-INF\services folder

And check the following URL to check the loading of the service

http://localhost:8080/axis2/services/listServices

The HelloWorldService should be visible as shown in the below picture


You might need to restart your Tomcat if the service “HelloWorldService” is not visible in the service console.

Use following URL to execute the web service

http://localhost:8080/axis2/services/HelloWorldService/getHello?username=Tom

You will get following response on your browser

- <ns:getHelloResponse xmlns:ns="http://demo.samples/xsd">
	  <ns:return>Hello World Mr Tom</ns:return>
  </ns:getHelloResponse>

Congratulations your Hello World web service is up and running

WSDL File

WSDL file can be viewed by URL

http://localhost:8080/axis2/services/HelloWorldService?wsdl

It can also be created by using ant command

%AXIS2_HOME%\bin\java2wsdl -cp . -cn samples.HelloWorldService -of HelloWorldService.wsdl

XSD File

XSD file can be viewed using following command

http://localhost:8080/axis2/services/HelloWorldService?xsd

Back | Tutorial Home | Next

site comments powered by Disqus
Download our free toolbar

toolbar powered by Conduit

| Copyright © 2009. All rights reserved | Terms and Conditions | About | Contact | Feed Back |