服务端:

需要导入的jar包

cxf开发webservice接口与调用

web.xml添加配置

cxf开发webservice接口与调用

spring-context.xml配置文件:

文件头中添加图片中的内容

cxf开发webservice接口与调用

然后配置内容,implementor中的路径为接口所在包名.类名。3.2版本cxf不需要引入配置文件(下图中注释部分)

cxf开发webservice接口与调用

测试接口示例:

cxf开发webservice接口与调用

至此服务端配置完成。

客户端:

需要导入的jar包

cxf开发webservice接口与调用

访问代码示例

cxf开发webservice接口与调用

运行结果

cxf开发webservice接口与调用

客户端访问方式还有很多种,示例方法只需要导入jar包,不需要任何配置,感觉比较方便。

soapUI测试

cxf开发webservice接口与调用

注:

  1. 其中wsdlUrl中192.168.0.118:8080是服务端ip:port,webservice为web.xml中配置的url-pattern,
    test为spring-context.xml中配置的address。
  2. myWebService为调用的方法名,若有参数可直接在invoke方法后按参数顺序添加,默认只支持简单参数类型。
  3. 要解决cxf webservice 生成wsdl方法参数名称为arg0问题,在服务器端的方法参数前添加@WebParam(name = “参数名称”)注解即可

相关文章: