简单实现
1.創(chuàng)建接口和實(shí)現(xiàn)類? (模擬實(shí)現(xiàn)查詢天氣)
?
接口:
package com.learning.weather;/*** * weather 接口 :實(shí)現(xiàn)模擬wsdl*/ public interface WeatherInterface {/*** 查詢天氣* @param name* @return*/public String queryWeather(String name); }?
實(shí)現(xiàn)類:
package com.learning.weather;import javax.jws.WebService;@WebService public class WeatherInterfaceImpl implements WeatherInterface {@Overridepublic String queryWeather(String name) {System.out.println("查詢天氣"+ name);return "nihao ";} }?
main方法測(cè)試,開(kāi)啟服務(wù):
package com.learning.weather;import javax.xml.ws.Endpoint;public class TestMain {public static void main(String[] args) {String address="Http://127.0.0.1:1234/weather";Object implementor=new WeatherInterfaceImpl();Endpoint.publish(address, implementor);}}?
訪問(wèn) Http://127.0.0.1:1234/weather,點(diǎn)擊wsdl
?
出現(xiàn)以下頁(yè)面
?
?在src目錄下 執(zhí)行wsimport命令? :? wsimport -p com.learning.client -s? .? http://127.0.0.1:1234/weather?wsdl
src下刷新出現(xiàn)新的包c(diǎn)om.learning.client
寫(xiě)客戶端程序
package com.learning.client;public class TestMain {public static void main(String[] args) {//1.創(chuàng)建服務(wù)視圖WeatherInterfaceImplService weatherInterfaceImplService =new WeatherInterfaceImplService();//2.得到實(shí)現(xiàn)類WeatherInterfaceImpl weatherInterfaceImpl = weatherInterfaceImplService.getPort(WeatherInterfaceImpl.class);//發(fā)送數(shù)據(jù)String weather = weatherInterfaceImpl.queryWeather("湖北");System.out.println(weather);} }運(yùn)行測(cè)試即可
?
轉(zhuǎn)載于:https://www.cnblogs.com/youwillsee/p/6817170.html
總結(jié)
- 上一篇: poj3264Balanced Line
- 下一篇: 为什么动物骨骼材料都是钙?其它金属、碳纤