客户端调用天气预报web service步骤

 
1. 利用XFire将 http://www.webservicex.net/globalweather.asmx?wsdl  天气预报的 webService 生成相应的客户端程序。具体步骤见 XFire根据WSDL生成客户端程序 http://blog.csdn.net/pengchua/archive/2007/08/02/1722156.aspx
2.  写调用 Test.java
package net.webservicex;
 
import java.util.Properties;
 
import org.dom4j.DocumentException;
 
import xml.TestXML;
 
public class Test {
 
       public static void main(String[] args) {
              // TODO Auto-generated method stub
              GlobalWeatherClient client = new GlobalWeatherClient();
              GlobalWeatherSoap GlobalWeather = client.getGlobalWeatherSoap();
              //如果是代理服务器就加上下面三句话就可了
              Properties prop = System.getProperties();
              prop.put("http.proxyHost","17.q31.1. 46");
              prop.put("http.proxyPort","8080");
 
//             System.out.println(GlobalWeather.getCitiesByCountry("china"));
              try {
                     TestXML.read(TestXML.StringToDocument(GlobalWeather.getWeather("Shanghai", "china")));
              } catch (DocumentException e) {
                     // TODO Auto-generated catch block
                     e.printStackTrace();
              }
       }
 
}
TestXML.javar的作用是解析XML,具体代码见:
java 解析 XML 方法 _dom4j http://blog.csdn.net/pengchua/archive/2007/08/23/1755441.aspx
 

你可能感兴趣的:(WebService)