Thursday, May 6, 2010

Java WebService Example : JAXWS

A Class which is a web service
package jaxws;
import javax.jws.WebMethod;
import javax.jws.WebService;

public class Hello {
private String message = "Hello, ";

public void Hello() {}

public String sayHello(String name) {
return message + name + ".";
A Class which exposes this web service

package jaxws;

public class Server {

protected Server () throws Exception {
System.out.println ("Starting Server");
Object implementor = new Hello ();
String address = "http://localhost:9000/SoapContext/SoapPort";
Endpoint.publish (address, implementor);

public static void main (String args[]) throws Exception {
new Server ();
System.out.println ("Server ready...");
System.out.println (" -- Press any key to exit..."); ();
System.out.println ("Server exiting");
System.exit (0);

Get the WSDL from Server : Open the url with your internet browser : http://localhost:9000/SoapContext/SoapPort?wsdl

Create a project for this wsdl via SOAPUI and send requests.So simple!

No comments:

Post a Comment