天天看点

用CXF来调用webService用CXF来调用webService

用CXF来调用webService

CXF发布服务,有三种形式:根据main方法发布【Java Project项目】;不基于Spring方式发布到Web容器中,比如Tomcat容器【web项目】;基于Spring方式发布到Web容器中。【web项目】

1. Java的webService实现本身就是一个很耗性能的实现方案(xml与java对象之间在服务端以及客户端的互转比较消耗性能)

2. 目前java主流的webService应用以CXF、AXIS2为主;

3. 通过网络渠道的了解,目前CXF的效率要比AXIS2高出至少50%;

4. CXF在java应用实现中已经很成熟,企业更倾向于用这样一个成熟的解决方案;

5. CXF和Spring高度集成。

1.通过CXF调用service的条件

<dependency>

   <groupId>org.apache.cxf</groupId>

   <artifactId>cxf-rt-frontend-jaxws</artifactId>

   <version>${cxf.version}</version>

</dependency>

<dependency>

   <groupId>org.apache.cxf</groupId>

   <artifactId>cxf-rt-transports-http</artifactId>

   <version>${cxf.version}</version>

</dependency>

<dependency>

   <groupId>org.apache.cxf</groupId>

   <artifactId>cxf-rt-transports-http-jetty</artifactId>

   <version>${cxf.version}</version>

</dependency>

2.通过CXF调用service的方法

Object[] invoke(String operationName,

              Object... params)

                throws Exception

Invokes an operation synchronously

Parameters:

operationName - The name of the operation to beinvoked. The service namespace will be used when looking up theBindingOperationInfo.

params - The params that matches theparts of the input message of the operation. If the BindingOperationInfosupports unwrapping, it assumes the params are in the "unwrapped"form. If params are in the wrapped form, use invokeWrapped

Returns:

The return values that matche the parts of the outputmessage of the operation

Throws:

Exception