天天看点

webservice 服务器端

创建一个java project。名称随意。我的工程名称为:webservice1

第一步:拷贝cxf提供的jar包.

第二步:编写webservice服务端的接口和实现类

接口

@WebService

public interface WeatherService {

   public String getWeatherByCityName(String cityName);

}

实现类

public class WeatherServiceImpl implements WeatherService {

@Override

public String getWeatherByCityName(String cityName) {

// TODO Auto-generated method stub

if("北京".equals(cityName))

return "万里无云";

else if("上海".equals(cityName))

return "小雨";

else if("信阳".equals(cityName))

return "阴天";

return "未知";

}

}

第三步:编写测试类(此处不能使用Junit,必须用main函数)

public class PublisherWeatherService {

public static void main(String[] args) {

// TODO Auto-generated method stub

JaxWsServerFactoryBean   factory=new JaxWsServerFactoryBean();

factory.setAddress("http://localhost:12345/weather");

factory.setServiceBean(new WeatherServiceImpl());

factory.create();

}

}

第四步:在浏览器中运行

http://localhost:12345/weather?wsdl

继续阅读