WebService接口代码的编写
如何编写一个webService接口,大家都知道webservice接口的好处可以跨平台来使用,在不同的编程语言之间可以实现,可以更容易的交互。
首先编写一个接口interface:
package com.camera.webservice;
public interface WeatherInterface {
String queryWeather(String cityName);
}
然后编写一个class类来继承实现这个接口:
package com.camera.webserviceimpl;
import javax.jws.WebService;
import com.camera.webservice.WeatherInterface;
@WebService
public class WeatherInterfaceImpl implements WeatherInterface{
@Override
public String queryWeather(String cityName) {
System.out.println("接收到客户端发送的城称:"+cityName);
String result="晴,高温预警";
return result;
}
}
编写了这些之后然后再编写一个服务:
package com.camera.webserviceimpl;
import javax.xml.ws.Endpoint;
public class WeatherServer {
public static void main(String[] args) {
//发布服务
Endpoint.publish("http://127.0.0.1:11111/weather", new WeatherInterfaceImpl());
}
}
然后访问这个网址:http://127.0.0.1:11111/weather?wsdl
上面就实现了一个webservice代码的编写