使用jaxws API 发布服务: package server; import javax.xml.ws.Endpoint; public class Server { protected Server() throws Exception { System.out.println("Starting Server"); MyHelloWorldImpl implementor = new MyHelloWorldImpl(); String address = "http://localhost:9000/myHelloWorld"; Endpoint.publish(address, implementor); } public static void main(String args[]) throws Exception { new Server(); System.out.println("Server ready..."); Thread.sleep(5 * 60 * 1000); System.out.println("Server exiting"); System.exit(0); } } 使用jaxws API处理客户端调用: package client; import java.net.MalformedURLException; import java.net.URL; import javax.xml.namespace.QName; import javax.xml.ws.Service; import server.MyHelloWorld; /** * 第二种访问方式 * @author FHD */ public class Client2 { public static void main(String[] args) { URL wsdlURL = null; try { wsdlURL = new URL("http://localhost:9000/myHelloWorld?wsdl"); } catch (MalformedURLException e) { e.printStackTrace(); } final QName SERVICE_NAME = new QName("http://server/", "FHDHelloWorld"); Service service = Service.create(wsdlURL, SERVICE_NAME); MyHelloWorld hw = service.getPort(MyHelloWorld.class); hw.sayHi("fuhaidong"); System.out.println("client: fuhaidong"); } }