版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/b509_ying/article/details/90755249
最近在写webservice接口,首先是用cxf发布了webservice接口,现在要求用axis2去远程调用cxf写的接口,遇到了一个错误:org.apache.axis2.AxisFault: The given SOAPAction aaa does not match an operation.
如下图:
不难看出,是因为使用CXF编写Web services客户端时生成的WSDL文件中没有提供soapAction的值,而客户端进行调用时 通过options.setAction(method)进行相应操作,所以发生错误。
所以,在cxf编写接口时,在接口上添加@WebMethod这个注解,将注解标示在Web Services的接口(Java语言中的)中,并提供action属性,如下图:
这样在客户端调用接口时就可以顺利访问到了。
服务端和客户端的代码贴上,方便大家理解
//服务端接口发布(cxf方式) public static void main(String[] args) { //cxf方式 System.out.println("web Service start"); HelloWorldImpl implementor = new HelloWorldImpl(); String address="http://localhost:8080/helloWorld"; JaxWsServerFactoryBean factoryBean = new JaxWsServerFactoryBean(); factoryBean.setAddress(address); //设置暴露地址 factoryBean.setServiceClass(HelloWorld.class); //接口类 factoryBean.setServiceBean(implementor); //设置实现类 factoryBean.create(); System.out.println("web Service started"); }
//客户端接口调用(axis2) public static final String targetEndpoint = "http://localhost:8080/helloWorld"; public static final String targetNamespace = "http://server.lin.com/"; public static final String method = "aaa"; public static String send() { try { RPCServiceClient client = new RPCServiceClient(); Options options = client.getOptions(); options.setTo(new EndpointReference(targetEndpoint)); options.setTimeOutInMilliSeconds(1000 * 60 * 5);// 毫秒单位 options.setAction(method); Object[] response = client.invokeBlocking(new QName(targetNamespace, method), new Object[]{"lin","1342"}, new Class[]{String.class}); String results = (String) response[0]; return results; } catch (Exception e) { e.printStackTrace(); return null; } }
文章来源: https://blog.csdn.net/b509_ying/article/details/90755249