Axis 2 WebService:调用方法时参数的数量错误

时间:2014-06-04 16:15:41

标签: java web-services soap tomcat7 axis2

我尝试使用axis2设置网络服务。 我使用Apache Tomcat 7和动态Web版本2.5在Eclipse下创建了一个Dynamic Web Projet。我已将Axis 2 Facets添加到配置中。

我有以下课程:

package com.jo.ws;

public class Test {
    public int add(int a, int b) {
        return a + b;
    }
}

然后我使用Bottom up Java bean Web Service为projet创建了一个WebService,并将我的Test类添加到服务实现中。 我选择了"开始服务"在滑块中,并将配置中的Apache Axis更改为Axis 2.然后,我使用默认选项生成默认的services.xml文件。

我可以通过以下地址访问我的项目:

http://localhost:8888/Axis2WS/

这会显示Axis 2页面,我可以看到我的服务处于活动状态

 http://localhost:8888/Axis2WS/services/listServices 

正确生成并显示wsdl

如果需要,我可以发布。

但现在如果我这样做:

http://localhost:8888/Axis2WS/services/Test?method=add&a=2&b=1

我明白了:

<soapenv:Reason xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Text xml:lang="en-US">wrong number of arguments</soapenv:Text>
</soapenv:Reason>

我的Eclipse控制台日志中也出现了错误,包含以下堆栈跟踪:

[ERROR] wrong number of arguments
java.lang.IllegalArgumentException: wrong number of arguments
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.java:178)
    at     org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.ja    va:117)
    at     org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMe    ssageReceiver.java:40)
    at     org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:114    )
    at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:181)
    at     org.apache.axis2.transport.http.util.RESTUtil.invokeAxisEngine(RESTUtil.java:144)
    at     org.apache.axis2.transport.http.util.RESTUtil.processURLRequest(RESTUtil.java:139)
    at     org.apache.axis2.transport.http.AxisServlet$RestRequestProcessor.processURLRequest(AxisServ    let.java:837)
    at org.apache.axis2.transport.http.AxisServlet.doGet(AxisServlet.java:273)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at     org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.jav    a:303)
    at     org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at     org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at     org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at     org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    at     org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at     org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
    at     org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:    607)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

知道我做错了什么吗?

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

错误来自我在浏览器中输入的网址.. 调用该方法的正确URL是:

http://localhost:8888/Axis2WS/services/Test/add?a=3&b=2

您需要更换&#34;?&#34;用&#34; /&#34;在方法名称之前,然后在添加&#34;?&#34;之后写下参数。在您的方法名称之后