package cn.ydq.ws; import javax.jws.WebMethod; import javax.jws.WebService; @WebService public interface WebServiceI { @WebMethod String sayHello(String name); @WebMethod String save(String name,String pwd); }
package cn.ydq.ws; import javax.jws.WebService; @WebService public class WebServiceImpl implements WebServiceI{ @Override public String sayHello(String name) { // TODO Auto-generated method stub return "hello,"+name; } @Override public String save(String name, String pwd) { // TODO Auto-generated method stub return "name="+name+",password="+pwd; } }
package cn.dyq.ws.test; import javax.xml.ws.Endpoint; import cn.ydq.ws.WebServiceImpl; public class WebServicePublish { public static void main(String[] args) { String address = "http://127.0.0.1:8989/WS_Server/WebService"; Endpoint.publish(address,new WebServiceImpl()); System.out.println("發佈webservice成功!"); } }
以上是服務端的代碼,那麼咱們如何在客戶端去調用這兩個方法呢?請看下面:java
打開瀏覽器,進入到http://127.0.0.1:8989/WS_Server/WebService web
進入到cmd命令窗口瀏覽器
就能夠看見生成的代碼了ide
package cn.ydq.ws.test; import cn.ydq.ws.WebServiceImpl; import cn.ydq.ws.WebServiceImplService; public class TestClient { public static void main(String[] args) { WebServiceImplService swis = new WebServiceImplService(); WebServiceImpl wsi = swis.getWebServiceImplPort(); String rs = wsi.sayHello("dengyuanqi"); System.out.println(rs); } }