如果找到了对您有用的资料,烦请点击右手边的Google广告支持我继续共享知识,谢谢! http://dengpeng.spaces.live.com/

2008年7月14日星期一

Simplest Java SE Web Service Tutorial

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) {
}
}
}
}





Read this document on Scribd: nb02-part6-jsews

没有评论: