web service 服务端:
package com.xh.ws; import javax.jws.WebMethod; import javax.jws.WebService; /** * * @author kali * SEI:使用注解定义 */ @WebService public interface HelloWS { @WebMethod public String sayHello(String s) ; }
package com.xh.ws.impl; import javax.jws.WebService; import com.xh.ws.HelloWS; /** * SEI的实现 * @author kali * */ @WebService public class HelloWsImpl implements HelloWS { @Override public String sayHello(String s) { // TODO Auto-generated method stub System.out.println("sayHello:"+s); return ">>>hello"+s; } }
服务端测试代码:
package com.xh.ws.test; import javax.xml.ws.Endpoint; import com.xh.ws.impl.HelloWsImpl; public class WS_sTest { public static void main(String[] args) { String address="http://127.0.0.1:8080/ws01/hello"; Endpoint.publish(address, new HelloWsImpl()); System.out.println("发布成功"); } }
web service 客户端:
客户端代码生成方法:
客户端测试代码:
package com.xh.ws.impl.test; import com.xh.ws.impl.HelloWsImpl; import com.xh.ws.impl.HelloWsImplService; public class WS_c_test { public static void main(String[] args) { HelloWsImplService factory=new HelloWsImplService(); HelloWsImpl helloWsImpl=factory.getHelloWsImplPort(); System.out.println(helloWsImpl.sayHello("zana")); } }