關於JDK的安裝及其配置請參閱其他文章,在此不再詳述。
Step 01: 選擇目前較新的Eclipse 版本。
Step 02:
取得對應的上海思集發布的WSDL的URL:
http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?WSDL
Step 03: File --》New --》Other
選中Web ServiceClient
點擊【Next】
點擊【Browse】, 輸入WSDL
點擊【Finish】產生的檔案目錄如下:
Step 04 建立TEST.JAVA
輸入如下代碼即可測試了。
packageweatherTest;
importjava.rmi.RemoteException;
importjavax.xml.rpc.ServiceException;
importcn.com.WebXml.WeatherWebServiceLocator;
importcn.com.WebXml.WeatherWebServiceSoap;
public classWeatherTest {
/**
* @paramargs
*/
public static voidmain(String[] args) {
// TODOAuto-generated method stub
StringtheCityName = "德州";
WeatherWebServiceSoap wwsopat;
java.lang.String[]city = null;
WeatherWebServiceLocatorDMSLocator = newWeatherWebServiceLocator();
System.out.print("test000000000000000000000000000 \n");
try {
wwsopat= DMSLocator.getWeatherWebServiceSoap();
city =wwsopat.getWeatherbyCityName(theCityName);
}catch (ServiceException e) {
// TODOAuto-generated catch block
e.printStackTrace();
}catch (RemoteException e) {
// TODOAuto-generated catch block
e.printStackTrace();
}
System.out.print("test111111111111111111111111111111 \n");
System.out.print("DESC:"+city.toString()+"\n");
}
}