WebService service publishing is often confusing, Axis2 publish form and Xfire publish way is very different, and JAVA6 Web Service Publishing and Axis2, Xfire Web Service Publishing Way is also a difference, they have no experience to learn from.
Therefore, it is necessary to delve into the way in which JAVA6 Web services are published.
As you can see from the previous two articles, JAVA6 provides API-level direct support for WebService's release, which is done with just one line of code. But as a service, you need to start, you can not start each time to run a Main method to start it.
The actual publication of Web services is often accompanied by the launch of the Web container, and in JAVA6 we cannot directly publish like Axis2 and Xfire, but we can work through the servlet to bind to the container and post the service at the start of the container.
Here's a example of Tomcat to implement the JAVA6 Web service publication.
1, the development of WebService services
package lavasoft.server;
import javax.jws.WebService;
/**
* Java6开发的WebService服务端
*
* @author leizhimin 2009-11-16 10:24:13
*/
@WebService
public class Java6WS {
/**
* Web服务中的业务方法
*
* @return 一个字符串
*/
public String doSomething(String username) {
return username + " is doing something!";
}
}
2, the development of the service servlet, in order to be universal, it is best to choose Genericservlet to inherit
Package Lavasoft.servlet
Import Lavasoft.server.Java6WS;
import javax.servlet.*;
Import Javax.xml.ws.Endpoint;
Import java.io.IOException;
/**
* publishes Java6 WebService servlet,
*
* @author leizhimin 2009-11-16 13:52:49
*/
public class Wsse Rvlet extends Genericservlet {
@Override
public void init (ServletConfig servletconfig) throws Se rvletexception {
Super.init (servletconfig);
System.out.println ("Ready to start WebService service: Http://192.168.14.117:8888/java6ws/Java6WS");
//Publish a WebService
Endpoint.publish ("Http://192.168.14.117:8888/java6ws/Java6WS"), New Java6ws ());
System.out.println ("Successfully started WebService service: Http://192.168.14.117:8888/java6ws/Java6WS");
}
public void service (ServletRequest servletrequest, Servletresponse servletresponse) throws Se Rvletexception, IOException {
SYSTEM.OUt.println ("This servlet does not handle any business logic, only Yonglai publish a Web service: Http://192.168.14.117:8888/java6ws/Java6WS");
}
}
Here the code for the Service release is written in the servlet init () method, and the method inside Init () is automatically executed when the servlet loads. To achieve the purpose of the publishing Service, because this servlet does not handle any business, so in the service only write a prompt statement.