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

本文详细解析了使用Axis2远程调用由CXF发布的Webservice接口时遇到的“SOAPAction不匹配”错误。通过在CXF接口上添加@WebMethod注解并设置action属性,解决了客户端无法正确访问接口的问题。文章附上了服务端和客户端的代码示例,便于读者理解和实践。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近在写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;
        }
    }

 

 

 

 

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值