webService demo
整体思路:建立两个java工程(一个服务端,一个客户端)- 发布服务 - 调用接口
1 建立工程
服务端:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
@WebService public class WebServiceS { public String isVava(String name){ if(name.equalsIgnoreCase("vava")){ return "vava queen"; } return "not vava"; } public String isPg1(String name){ if(name.equalsIgnoreCase("pg1")){ return "the one"; } return "not the one"; } public static void main(String[] args) { Endpoint.publish("http://localhost:8081/WebServiceS", new WebServiceS()); } }
客户端:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
public class WebServiceC { public static void main(String[] args) { WebServiceSService ws = new WebServiceSService(); WebServiceS wss = ws.getWebServiceSPort(); String pg = wss.isPg1("pg1"); String vaVa = wss.isVava("vava"); System.out.println(pg); System.out.println(vaVa); } }
2 发布服务
即启动服务端程序,并访问:http://localhost:8081/WebServiceS?wsdl
若启动成功,则如下图:
3 调用接口
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
WebServiceSService ws = new WebServiceSService(); WebServiceS wss = ws.getWebServiceSPort(); String pg = wss.isPg1("pg1"); String vaVa = wss.isVava("vava"); System.out.println(pg); System.out.println(vaVa);