To create a Web Service using the Java-WS specification, you need several artifacts. The purpose of "apt", "wsgen" and "wsimport" is to automate this procedure.
There are two ways to create a Web Service: Bottom-Up (First code, then WSDL) and Top-Down (First WSDL then code).
Bottom-Up approach:
- apt: Uses source code, generates WSDL (and artifacts)
- wsgen: Uses compiled code, generates WSDL (and artifacts)
Top-Down
- wsimport: Uses the WSDL, generates java code for the service/client implementation.
The advantage of using apt is that having the source code the script will be able to get the parameters names and use them on the WSDL.
Web Service Deployment
For production you would need a Web Container which can be in charge of security, scalability and resource management, however, for testing purposes you can deploy your web services using the built-in web server on Java SE by doing:
@WebService
public class MyService {
public static void main(String args[]) {
MyService service = new MyService();
String url = "service/";
Endpoint ep = new Endpoint(url, service);
}
@WebMethod
public String getInfo() {
return "Service info";
}
}
This piece of code would generate the WSDL and publish the service at your localhost/service.