Step 1:Create these two files
HelloWorld.java
package helloworld; public interface HelloWorld { public String sayHello(String name); }
HelloWorldImpl.java
package helloworld; public class HelloWorldImpl implements HelloWorld { public String sayHello(String name) { if (name == null) return "Hello Everyone"; else return "Hello " + name; } }
Put these in the directory
CATALINA_HOME\webapps\axis\WEB-INF\classes\helloworld
Step 2 Run this command
java org.apache.axis.wsdl.Java2WSDL -o hello.wsdl -l http://localhost:8080/axis/services/helloworld -n urn:helloworld -p"helloworld" urn:helloworld helloworld.HelloWorldThis will generate the wsdl file
<?xml version="1.0" encoding="UTF-8"?> <wsdl:definitions targetNamespace="urn:helloworld" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="urn:helloworld" xmlns:intf="urn:helloworld" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <!--WSDL created by Apache Axis version: 1.3 Built on Oct 05, 2005 (05:23:37 EDT)--> <wsdl:message name="sayHelloRequest"> <wsdl:part name="in0" type="soapenc:string"/> </wsdl:message> <wsdl:message name="sayHelloResponse"> <wsdl:part name="sayHelloReturn" type="soapenc:string"/> </wsdl:message> <wsdl:portType name="HelloWorld"> <wsdl:operation name="sayHello" parameterOrder="in0"> <wsdl:input message="impl:sayHelloRequest" name="sayHelloRequest"/> <wsdl:output message="impl:sayHelloResponse" name="sayHelloResponse"/> </wsdl:operation> </wsdl:portType> <wsdl:binding name="helloworldSoapBinding" type="impl:HelloWorld"> <wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="sayHello"> <wsdlsoap:operation soapAction=""/> <wsdl:input name="sayHelloRequest"> <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:helloworld" use="encoded"/> </wsdl:input> <wsdl:output name="sayHelloResponse"> <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:helloworld" use="encoded"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="HelloWorldService"> <wsdl:port binding="impl:helloworldSoapBinding" name="helloworld"> <wsdlsoap:address location="http://localhost:8080/axis/services/helloworld"/> </wsdl:port> </wsdl:service> </wsdl:definitions>
Step 3 Run this command
java org.apache.axis.wsdl.WSDL2Java -o . -d Session -s -p helloworld.gen hello.wsdlThis will take as input the wsdl file and generate various java stub files. The -s flag tells the program to generate server side code, and the -p flag tells the program where to put the code.
This will produce the following files
HelloWorld.java
HelloWorldService.java
HelloWorldServiceLocator.java
HelloWorldSoapBindingImpl.java
HelloWorldSoapBindingStub.java
deploy.wsdd
undeploy.wsdd
Step 4
Deploy the server
Compile the code, create a jar file and deploy the WSDD file
Step 5: Write the client
package helloworld; import helloworld.gen.*; public class HelloWorldTester { public static void main(String[] args) throws Exception { HelloWorldService service = new HelloWorldServiceLocator(); helloworld.gen.HelloWorld hello = service.gethelloworld(); System.out.println(hello.sayHello("Suzy Creamcheese")); } }