CXF简介

1.下载CXF

   CXF是XFire的升级半,XFire已经停止更新了

    让后将lib下所有jar包(可能有些jar包不需要,还没研究)添加到BuildPath下

 

2.编写接口

   

@WebService
public interface JtllWebServices {
/**

* @param type
* @return
*/
String jtllWs(@WebParam(name="type")String type);
}

 

  3.编写实现类

@WebService(endpointInterface = "com.wh.app.jsjt.jtll.webservices.JtllWebServices", serviceName = "JtllWebServices",targetNamespace="http://webservices.jtll.jsjt.app.wh.com/")
public class JtllWebServicesImpl implements JtllWebServices{
@Override
public String jtllWs(String type) {
JtllManager.jtllInit();
return type;
}
}

 

4.通过CXF内置Jetty Servelet容器发布服务

JtllWebServices ws = new JtllWebServicesImpl();
String address="http://localhost:8080/JtllWebServices";
        Endpoint.publish(address, ws);

 http://localhost:8080/JtllWebServices?wsdl 录入地址栏,回车,你就可以看到wsdl描述

 

5.客户端

Java代码 
  1. //依赖接口
    /*JaxWsProxyFactoryBean svr = new JaxWsProxyFactoryBean();
             svr.setServiceClass(JtllWebServices.class);
             svr.setAddress("http://localhost:8080/JtllWebServices");
             JtllWebServices hw = (JtllWebServices) svr.create();
             System.out.println(hw.jtllWs(""));*/
    //不依赖服务器端接口来完成调用的,也就是不仅仅能调用Java的接口
    JaxWsDynamicClientFactory clientFactory = JaxWsDynamicClientFactory.newInstance();
    Client client =  clientFactory.createClient("http://192.168.1.114:8080/JtllWebServices?wsdl");
    Object[] result = client.invoke("jtllWs","000");

 

 注:JaxWsDynamicClientFactory 时,要在实现类加上targetNamespace="http://webservices.jtll.jsjt.app.wh.com/"

你可能感兴趣的:(CXF)