import javax.jws.WebMethod; import javax.jws.WebService; @WebService public class HelloWorld { @WebMethod public String sayHello(String name) { return "Hello " + name; } } import javax.xml.ws.Endpoint; public class HelloWorldPublisher { public static void main(String[] args) { String url = "http://localhost:8080/helloWorld"; Endpoint.publish(url, new HelloWorld()); System.out.println("Web service is published at " + url); } } import javax.xml.namespace.QName; import javax.xml.ws.Service; import java.net.URL; public class HelloWorldClient { public static void main(String[] args) throws Exception { URL url = new URL("http://localhost:8080/helloWorld?wsdl"); QName qname = new QName("http://webservice.example.com/", "HelloWorldService"); Service service = Service.create(url, qname); HelloWorld hello = service.getPort(HelloWorld.class); System.out.println(hello.sayHello("World")); } }


上一篇:
下一篇:
切换中文