- RESTful services are stateless. Each request from a client to a server must contain all the information necessary to understand the request and must not depend on any stored contextual information on the server.
- REST-ful services have a uniform interface. For example for a RESTful HTTP service, the operation supported are GET, POST, PUT and DELETE.
- REST based architectures are built from resources which are identified by unique URI's.
- REST components manipulate resources by exchanging representations of the resources.
The fundamental differences between REST and RPC based services can be outlined as
- RPC services work by invoking a procedure on a server rather than by exchanging representations of a resource.
- In the RPC approach typically many operations are invoked at the same URI, which is fundamentally different from the REST way where every resource has a unique URI.
XML | XML inside a SOAP envelope |
none | WSDL |
HTTP | HTTP,FTP,MIME,JMS,SMTP etc |
In order to consume a RESFful service using JAX-WS 2.0, the majority of the work needs to be done using the javax.xml.ws.Dispatch
The following code displays the basics and is discussed below
QName svcQName = new QName("http://xyz", "svc");
QName portQName = new QName("http://xyz", "port");
Service svc = Service.create(svcQName);
svc.addPort(portQName, HTTPBinding.HTTP_BINDING, args[0]);
Dispatch
- The client uses the Service.addPort() method to create a port within the Service instance that can be used to access the RESTful Web service.
- Next, the Service.createDispatch() method is invoked to create an instance of Dispatch
- The Dispatch.invoke() method then packages the XML request—per the JAX-WS 2.0 HTTP Binding—and sends it to the RESTful service. The invoke() method waits for the response before returning.
- The service processes the HTTP GET and sends an HTTP response that includes the XML.
- The invoke() method returns the response XML message as an instance of Source.