Remote Procedure Calls With JAX-WS

SENG 41283 — Distributed and Cloud Computing

Web Services

1. “Big” Web Services.

2. RESTful Web Services

Jakarta XML Web Services (JAX-WS)

Building a Hello World web service with JAX-WS (RPC style)

package se.jax_ws;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;

//Service Endpoint Interface
@WebService
@SOAPBinding(style = Style.RPC)
public interface HelloWorld
{
@WebMethod
String getHelloWorldAsString(String name);
}
package se.jax_ws;

import javax.jws.WebService;

//Service Implementation
@WebService(endpointInterface = "se.jax_ws.HelloWorld")
public class HelloWorldImpl implements HelloWorld
{
@Override
public String getHelloWorldAsString(String name)
{
return "Hello from JAX-WS " + name;
}
}
package se.jax_ws;

import javax.xml.ws.Endpoint;

//Endpoint publisher
public class HelloWorldPublisher
{
public static void main(String[] args)
{
Endpoint.publish("http://localhost:9999/ws/hello",
new HelloWorldImpl());
}
}
package se.jax_ws;

import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;

public class HelloWorldClient
{
public static void main(String[] args) throws Exception
{
URL url = new URL("http://localhost:9999/ws/hello?wsdl");

//1st argument service URI, refer to wsdl document above
//2nd argument is service name, refer to wsdl document above
QName qname = new QName("http://jax_ws.se/",
"HelloWorldImplService");
Service service = Service.create(url, qname);
HelloWorld hello = service.getPort(HelloWorld.class);
System.out.println(hello.getHelloWorldAsString("John Doe"));
}
}
Hello from JAX-WS John Doe