1、天氣預(yù)報(bào)web services地址
http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl用瀏覽器打開(kāi)此地址,保存頁(yè)面為Weather.xml
2、新建一個(gè)java工程 webservices
建立包名 com.test.ws
將Weather.xml拷貝到src目錄下
3、編寫批處理
WSDL-SQUARED.CMD,使用wsdj2java生成客戶端調(diào)用代碼
set AXIS_HOME=D:\axis-1_4
set CLASSPATH=.;%AXIS_HOME%\lib\axis.jar;%AXIS_HOME%\lib\axis-ant.jar;%AXIS_HOME%\lib\commons-discovery-0.2.jar;%AXIS_HOME%\lib\commons-logging-1.0.4.jar;%AXIS_HOME%\lib\jaxrpc.jar;%AXIS_HOME%\lib\log4j-1.2.8.jar;%AXIS_HOME%\lib\saaj.jar;%AXIS_HOME%\lib\wsdl4j-1.5.1.jar
java org.apache.axis.wsdl.WSDL2Java -p com.test.ws Weather.xml
首先需要配置AXIS的HOME路徑,后面是指定輸出包名,以及指定wsdl描述文件,也可以是前面提到的webservice地址
4、打開(kāi)命令行,切換目錄到工程的src文件下,輸入WSDL-SQUARED執(zhí)行批處理文件
5、刷新工程,我們可以看到在com.test.ws目錄下生成了很多java代碼
6、新建測(cè)試類
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import com.strongit.ws.WeatherWS;
import com.strongit.ws.WeatherWSLocator;
import com.strongit.ws.WeatherWSSoap_PortType;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) Strongit 2011</p>
* <p>Company: </p>
* @author lanjinghui@foxmail.com
* @version 1.0
*/
public class WeatherClient {
/**
* @Description 方法實(shí)現(xiàn)功能描述
* @author lanjh 下午10:04:23
* @return void
* @throws 拋出異常說(shuō)明
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
WeatherWS weatherWS = new WeatherWSLocator();
try {
WeatherWSSoap_PortType weatherWSSoap_PortType = weatherWS.getWeatherWSSoap();
// String[] provs = weatherWSSoap_PortType.getRegionProvince();
// for(String p : provs){
// System.out.println(p);
// }
//
//
// System.out.println("------------------------------------");
//
//
// String[] citys = weatherWSSoap_PortType.getSupportCityString("江西");
// for(String c : citys){
// System.out.println(c);
// }
System.out.println("------------------------------------");
//南昌,2117
String[] weather = weatherWSSoap_PortType.getWeather("南昌", null);
for(String w : weather){
System.out.println(w);
}
} catch (ServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
7、運(yùn)行結(jié)果
- Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart). Attachment support is disabled.
------------------------------------
江西 南昌
南昌
2117
2011/07/13 09:38:13
今日天氣實(shí)況:氣溫:26℃;風(fēng)向/風(fēng)力:東北風(fēng) 2級(jí);濕度:82%
空氣質(zhì)量:良;紫外線強(qiáng)度:中等
穿衣指數(shù):天氣較熱,建議著短裙、短褲、短套裝、T恤等夏季服裝。年老體弱者宜著長(zhǎng)袖襯衫和單褲。
感冒指數(shù):各項(xiàng)氣象條件適宜,發(fā)生感冒機(jī)率較低。但請(qǐng)避免長(zhǎng)期處于空調(diào)房間中,以防感冒。
運(yùn)動(dòng)指數(shù):白天有降水,建議在戶內(nèi)進(jìn)行輕度運(yùn)動(dòng)。若堅(jiān)持戶外運(yùn)動(dòng),請(qǐng)選擇合適的運(yùn)動(dòng),并攜帶雨具。
洗車指數(shù):不宜洗車,未來(lái)24小時(shí)內(nèi)有雨,如果在此期間洗車,雨水和路上的泥水可能會(huì)再次弄臟您的愛(ài)車。
晾曬指數(shù):有降水,不適宜晾曬。如果非晾曬不可,請(qǐng)?jiān)谑覂?nèi)準(zhǔn)備出充足的空間。
旅游指數(shù):有雷陣雨,稍熱,微風(fēng),旅游指數(shù)一般,外出請(qǐng)盡量避開(kāi)雷陣雨時(shí)間,若外出,請(qǐng)注意防雷并攜帶雨具。
路況指數(shù):有小雨,路面潮濕,車輛易打滑,請(qǐng)小心駕駛。
舒適度指數(shù):白天雖然有雨,但仍無(wú)法削弱較高氣溫帶來(lái)的暑意,同時(shí)降雨造成濕度加大會(huì)您感到有些悶熱,不很舒適。
空氣污染指數(shù):氣象條件有利于空氣污染物稀釋、擴(kuò)散和清除,可在室外正常活動(dòng)。
紫外線指數(shù):屬中等強(qiáng)度紫外線輻射天氣,外出時(shí)建議涂擦SPF高于15、PA+的防曬護(hù)膚品,戴帽子、太陽(yáng)鏡。
7月13日 雷陣雨
26℃/31℃
無(wú)持續(xù)風(fēng)向微風(fēng)
4.gif
4.gif
7月14日 陣雨
26℃/31℃
無(wú)持續(xù)風(fēng)向微風(fēng)
3.gif
3.gif
7月15日 陣雨
26℃/31℃
無(wú)持續(xù)風(fēng)向微風(fēng)
3.gif
3.gif
7月16日 陣雨
26℃/31℃
無(wú)持續(xù)風(fēng)向微風(fēng)
3.gif
3.gif
7月17日 陣雨
26℃/31℃
無(wú)持續(xù)風(fēng)向微風(fēng)
3.gif
3.gif