WebService报错:org.apache.axis2.AxisFault: The given SOAPAction aaa does not match an operation.

最近在写webservice接口,首先是用cxf发布了webservice接口,现在要求用axis2去远程调用cxf写的接口,遇到了一个错误:org.apache.axis2.AxisFault: The given SOAPAction aaa does not match an operation.

如下图:WebService报错:org.apache.axis2.AxisFault: The given SOAPAction aaa does not match an operation._第1张图片

不难看出,是因为使用CXF编写Web services服务端时生成的WSDL文件中没有提供soapAction的值,而客户端进行调用时 通过options.setAction(method)进行相应操作,所以发生错误。

所以,在cxf编写接口时,在接口上添加@WebMethod这个注解,将注解标示在Web Services的接口(Java语言中的)中,并提供action属性,如下图:

WebService报错:org.apache.axis2.AxisFault: The given SOAPAction aaa does not match an operation._第2张图片

这样在客户端调用接口时就可以顺利访问到了。

服务端和客户端的代码贴上,方便大家理解

//服务端接口发布(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;
        }
    }

 

 

 

 

你可能感兴趣的:(Webservice)