使用CXF开发Web Service的服务端

首先编写要发布的方法接口:
@WebService
public interface HelloWorld {

public String sayHi(String name);

}
接口此处必须添加@WebService

接口的实现类:
@WebService(endpointInterface="com.hlt.cxf.ws.HelloWorld"
,serviceName="HelloWorldWs")
public class HelloWorldWs implements HelloWorld{
      @Override
      public String sayHi(String name) {
return name + ",您好,现在的时间是:" + new  Date();
}

实现类中的@WebService中的endpointInterface必须是写该接口的全路径,服务名称可以随意写,一般就是实现类的名称。

发布该服务:
public class ServerMain {

public static void main(String[] args) {
//服务端ip地址
String address = "http://192.168.1.104/ws";

//要发布的Web Service的对象
HelloWorld hw = new HelloWorldWs();

//调用Endpoint的publish方法发布Web Service
Endpoint.publish(address, hw);

System.out.println("发布web server成功... ");
}
}

猜你喜欢

转载自daffy.iteye.com/blog/1940862