3.天气预报:编写客户端的主类

package com.bjpowernode.ws;

import java.rmi.RemoteException;

import javax.xml.rpc.ServiceException;

public class WeatherClient {

	/**
	 * WSDL、服务端已经开发好,客户端静态调用服务端开放的服务(看到存根、骨架,因为是静态的) 
     * 客户端要跟远端服务器打交道,实际上并不是直接打交道,而是通过远端服务器的代理,即是跟存根打交道,所以客户端 
     * 必须得到存根 
	 * @param args
	 * @throws ServiceException 
	 * @throws RemoteException 
	 */
	public static void main(String[] args) throws ServiceException, RemoteException {
		// 接口com.bjpowernode.ws.WeatherWebService可以通过getWeatherWebServiceSoap()得到存根,   
		// 而类com.bjpowernode.ws.WeatherWebServiceLocator是对该接口的实现
		 WeatherWebService weatherWebService = new WeatherWebServiceLocator();
		 
		 try {
			WeatherWebServiceSoap_PortType weatherWebServiceSoap_PortType = weatherWebService.getWeatherWebServiceSoap();
			
			System.out.println("本天气预报支持的省份如下:");
			String[] provinces = weatherWebServiceSoap_PortType.getSupportProvince();
			for (String province : provinces) {
				System.out.println(province);
			}
			System.out.println("----------------------------------");
			
			System.out.println("本天气预报支持的城市如下:");
			String[] cities = weatherWebServiceSoap_PortType.getSupportCity("湖南");
			for (String city : cities) {
				System.out.println(city);
			}
			System.out.println("----------------------------------");
			
			System.out.println("广州三天内的天气情况如下:");
			String[] weatherForThreeDay = weatherWebServiceSoap_PortType.getWeatherbyCityName("深圳");
			for (String weather : weatherForThreeDay) {
				System.out.println(weather);
			}
			System.out.println("----------------------------------");
			
			
			// 把截取到的异常往上抛
		} catch (ServiceException e) {
			e.printStackTrace();
			throw e;
		} catch (RemoteException e) {
			e.printStackTrace();
			throw e;
		}
	}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值