客户端程序代码如下:
//IGetWeatherTest.java
package test;import java.net.MalformedURLException;
import com.wxj.webservice.biz.IGetWeather;import mywebservice.MyWebService;
import org.junit.Test;public class IGetWeatherTest { @Test
public void testWeather() {
/*
//创建天气预报Web服务的元数据
Service service = new ObjectServiceFactory().create(IGetWeather.class);
//创建Web服务的代理
XFire xFire = XFireFactory.newInstance().getXFire();
XFireProxyFactory factory = new XFireProxyFactory(xFire);
//获取天气预报的Web服务的地址
String url = "http://localhost:8080/myWebService/services/Weather";
//生成天气预报Web服务调用对象
try {
IGetWeather ig = (IGetWeather) factory.create(service, url);
System.out.println(ig.weather());
} catch (MalformedURLException e) {
e.printStackTrace();
}*/

String url = "http://localhost:8080/myWebService/services/Weather";
try {
IGetWeather ig = (IGetWeather) MyWebService.findService(IGetWeather.class, url);
System.err.println(ig.weather());
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}}
服务端程序:
//WeatherImpl.java
package com.wxj.webservice.impl;import com.wxj.webservice.biz.Iweather;public class WeatherImpl implements Iweather { public String weather() {
return "晴朗";
}}
//Iweather.java
package com.wxj.webservice.biz;public interface Iweather {
String weather();
}现在在客户端测试的时候应经能产生正确输出,现在想写一个jsp页面,调用客户端程序,并将返回的结果传给服务器