1. 编写SEI(Service Endpoint Interface),SEI在webservice中称为portType,在java中就是普通接口
public interface WeatherInterface {
public String queryWeather(String cityName);
}
2. 编写SEI实现类,此类作为webservice提供服务类
@WebService //@WebService表示该类是一个服务类,需要发布其中的public的方法
public class WeatherInterfaceImpl implements WeatherInterface {
@Override
public String queryWeather(String cityName) {
System.out.println("获取城市名"+cityName);
String weather="暴雨";
return weather;
}
}
3. 第三步:发布服务,Endpoint类发布服务,publish方法,两个参数:1.服务地址;2.服务实现类
public class WeatherServer {
public static void main(String[] args) {
Endpoint.publish("http://127.0.0.1:12345/weather", new WeatherInterfaceImpl());
}
}
4. 测试服务是否发布成功,通过阅读wsdl,确定客户端调用的接口、方法、参数和返回值存在,证明服务发布成功
//我们在浏览器输入 http://127.0.0.1:12345/weather?wsdl 来获取wsdl文件进行阅读
//wsdl,是以XML文件形式来描述WebService的”说明书”,有了说明书,我们才可以知道如何使用或是调用这个服务.
//现在我们还不知道怎么去阅读,后面我们会详解,只要能获取到,就能确定WebService服务发布成功