import javax.jws.WebService; @WebService public interface HelloWorld { String sayHello(String name); } import javax.jws.WebService; @WebService(endpointInterface = "com.example.HelloWorld") public class HelloWorldImpl implements HelloWorld { 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 HelloWorldImpl()); } } import javax.xml.namespace.QName; import javax.xml.ws.Service; import com.example.HelloWorld; public class HelloWorldClient { public static void main(String[] args) throws Exception { String url = "http://localhost:8080/helloWorld?wsdl"; QName qname = new QName("http://example.com/", "HelloWorldImplService"); Service service = Service.create(new URL(url), qname); HelloWorld hello = service.getPort(HelloWorld.class); System.out.println(hello.sayHello("John")); } }


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