Interface
package com.liguoliang.soap.jaxws; import javax.jws.WebMethod; import javax.jws.WebService; import javax.jws.soap.SOAPBinding; import javax.jws.soap.SOAPBinding.Style; @WebService @SOAPBinding(style = Style.RPC) public interface IHelloWorld { @WebMethod String getHelloWorldAsString(String name); }
Implement:
package com.liguoliang.soap.jaxws; import javax.jws.WebService; @WebService(endpointInterface = "com.liguoliang.soap.jaxws.IHelloWorld") public class HelloWorldImpl implements IHelloWorld { @Override public String getHelloWorldAsString(String name) { return "Hello: " + name; } }
package com.liguoliang.soap.jaxws; import javax.xml.ws.Endpoint; public class HelloWorldPublisher { public static void main(String[] args) { Endpoint.publish("http://localhost:8080/ws/hello", new HelloWorldImpl()); } }
package com.liguoliang.soap.client; import java.net.MalformedURLException; import java.net.URL; import javax.xml.namespace.QName; import javax.xml.ws.Service; import com.liguoliang.soap.jaxws.IHelloWorld; public class HelloWorldClient { public static void main(String[] args) throws MalformedURLException { URL url = new URL("http://localhost:8080/ws/hello?wsdl"); QName qName = new QName("http://jaxws.soap.liguoliang.com/", "HelloWorldImplService"); Service service = Service.create(url, qName); // Get the instance. IHelloWorld iheHelloWorld = service.getPort(IHelloWorld.class); System.out.println(iheHelloWorld.getHelloWorldAsString("liguoliang.com")); } }
The outupt:
Hello: liguoliang.com
Design pattern:Adapter 设计模式:适配器 <->
// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.