Implementing web service
Endpoint/Client with JAX WS
Developing
Web Service End Point
1)
In Eclipse create a java project
"JAXWS-Server".
2)
Create JAXWS-Service Endpoint Interface:
--------------------------------------------------------------------------
package mysimple.example.define;
import javax.jws.WebMethod;
import javax.jws.WebService;
@WebService
public interface Greeting {
@WebMethod String sayHello(String
name);
}
--------------------------------------------------------------------------
3)
Create JAXWS-Service Endpoint Implementation class:
--------------------------------------------------------------------------
package mysimple.example.define;
import javax.jws.WebService;
@WebService(endpointInterface =
"mysimple.example.define.Greeting")
public class GreetingImpl implements
Greeting {
@Override
public String sayHello(String name) {
return "Hello, This is simplest
JAX-WS example By :: " + name;
}
}
--------------------------------------------------------------------------
4)
Create Endpoint Publisher class:
--------------------------------------------------------------------------
package mysimple.example.publish;
import javax.xml.ws.Endpoint;
import
mysimple.example.define.GreetingImpl;
public class WSPublisher {
public static void main(String[] args)
{
Endpoint.publish("http://localhost:8080/WS/Greeting",new
GreetingImpl());
}
}
--------------------------------------------------------------------------
5)
Run the WSPublisher….and your WebService is published.
Check the service wsdl http://localhost:8080/WS/Greeting?wsdl
Developing Web Service
Client :
1)
In eclipse create a new java project JAXWS-Client
2)
we need to generate the client stubs by following command(on the src path)
Command :
wsimport -keep -verbose http://localhost:8080/WS/Greeting?wsdl
|
- Remove all the class files
- Create the Client Class which will be dependent on the stubs
--------------------------------------------------------------------------
package mysimpleexample.client;
import
mysimple.example.define.Greeting;
import
mysimple.example.define.GreetingImplService;
public class Client {
public static void main(String[] args){
GreetingImplService service = new
GreetingImplService();
Greeting greeting =
service.getGreetingImplPort();
System.out.println("------->> Call Started");
System.out.println(greeting.sayHello("Manish_Kumar_Jaiswal"));
System.out.println("------->> Call Ended");
}
}
--------------------------------------------------------------------------
- Output :
------->> Call Started
Hello, This is simplest JAX-WS example
By :: Manish_Kumar_Jaiswal
------->> Call Ended
No comments:
Post a Comment