|
The Java SE 6 software includes a full web services client stack and supports the latest web services specifications and it provides expanded tools for diagnosing, managing and monitoring applications such as:
- JAX-WS 2.0,
- JAXB 2.0, STAX and JAXP and it includes a new layout manager component, based on the NetBeans GUI Builder (formerly code named Matisse).
- SOAP 1.2
-
- XML-binary Optimized Packaging(XOP) and SOAP Message Transmission Optimization Mechanism(MTOM)
Java SE 6 provides support for the JAX- WS web services stack.
- For the client side: Service class for creating proxy.
- For the server side: Endpoint class for publication.
Server-Side Programming Model
- Write a Plain Old Java Object implementing the web service.
- Add @WebService to it.
- Optionally, add a WebServiceContext
- Publish the Web service endpoint through Endpoint.publish() method. Web Service Description Language (WSDL) is automatically generated at runtime. The publish methods can be used to start publishing an endpoint, at which point it starts accepting incoming requests and the stop method can be used to stop accepting incoming requests and take the endpoint down.
-
- Point your clients at the Web Service Description Language (WSDL), for example:
http://myserver/myapp/MyService
publishing endpoint creates WSDL and publishes it at runtime.
http://localhost/sum
Let's take an example:
@WebService
Public class Sum
{
@Resource
WebServiceContext ctx;
public int add(int a, int b)
{
return a+b;
}
}
//Create and publish an endpoint
Sum sum=new Sum();
Endpoint endpoint = Endpoint.publish
(http://localhost/sum,sum);
Client-side Programming Model
- Point a tool at the WSDL for the service
- Generate annotated classes and interfaces through a tool.
- Call new on the service class.
- Get a proxy using a getxxxPort method.
-
- Invoke any remote operations.
Let's take an example:
//Create a Service object
SumService sumsrv=new SumService();
// Create a proxy from the Service object
Sum proxy=sumsrv.getSumPort();
//Invoke a Web Service operation
int answer=proxy.add(4,5); |