CircleFunctions.java
package geometricalws;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
@WebService(name = "Circle", serviceName = "CircleService", portName = "CirclePort")
@SOAPBinding(style = SOAPBinding.Style.RPC)
public class CircleFunctions {
@WebMethod(operationName = "area")
public double getArea(@WebParam(name = "r") double r) {
return Math.PI * (r * r);
}
@WebMethod(operationName = "circumference")
public double getCircumference(@WebParam(name = "r") double r) {
return 2 * Math.PI * r;
}
}
Main.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package geometricalws;
import javax.xml.ws.Endpoint;
/**
*
* @author Administrator
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String wsAddress = "http://localhost:8765/GeometricalWS/CircleFunctions";
Endpoint.publish(wsAddress, new CircleFunctions());
System.out.println("Web service was published successfully.\n" +
"WSDL URL: " + wsAddress + "?WSDL");
// Keep the local web server running until the process is killed
while (Thread.currentThread().isAlive()) {
try {
Thread.sleep(10000);
} catch (InterruptedException ex) {
}
}
}
}
没有评论:
发表评论