Now JAX-RPC has been replaced by new standard JAX-WS, so I thought it is good time to write an entry for JAX-WS as well. Building web services with JAX-WS is pretty straight forward though it might look cumbersome to a newbie. In this entry I am going explain the basic steps for building a Java first web service, which I developed and tested with JAX-WS 2.1.4, Java 6 update 6 and Tomcat 6.0.16.
Step #1 - Write an interface
@WebService(targetNamespace = "http://vinodsingh.com", name = "MyService")
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.LITERAL)
public interface MyService {
String sayHello(@WebParam(name = "name") String name);
}Step #2 - Implement the interface
@WebService(endpointInterface = "pkg.MyService")
public class MyServiceImpl implements MyService {
@Override
public String sayHello(String name) {
return "Hello " + name + "!";
}
}Step #3 - Configure web.xml
The JAX-WS context listener and servlet are required to be configured in deployment descriptor (web.xml). The WSServletContextListener initializes and configures the web service endpoint and WSServlet serves the service requests using implementing class.
----------------------------
<listener>
<listener-class>
com.sun.xml.ws.transport.http.servlet.WSServletContextListener
</listener-class>
</listener>
<servlet>
<servlet-name>jaxws
<servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet
</servlet>
<servlet-mapping>
<servlet-name>jaxws
<url-pattern>/myService
</servlet-mapping>
-----------------------------
Step #4 - sun-jaxws.xml
The JAX-WS RI uses information available in this file while initializing and configuring a web service endpoint. This file should be present in WEB-INF directory.
<endpoints
xmlns='http://java.sun.com/xml/ns/jax-ws/ri/runtime'
version='2.0'>
<endpoint
name='myService'
implementation='pkg.MyServiceImpl'
url-pattern='/myService' />
</endpoints>
For more information about this example, please go to below link which is the main link where i got the data.
http://blog.vinodsingh.com/2008/09/building-jax-ws-web-service.html
For jax-rpc example please use the below link
http://blog.vinodsingh.com/2007/08/bottom-up-jax-rpc-web-service-with.html
This blog contains the info about Java and J2ee and Ajax and Hibernate
Thursday, October 29, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment