在网上学习看ws写的类
package cn.dhcc.axis2;
import javax.xml.namespace.QName;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;
import org.apache.axis2.addressing.EndpointReference;
public class RPCClient {
//
private final static String SERVICEEPR = "http://localhost:8080/axis2/services/SimpleService";
private final static String NS = "http://ws.apache.org/axis2";
private static EndpointReference targetEPR = new EndpointReference(SERVICEEPR); //指定调用webserice的url
public static void main(String[] args) throws Exception{
//使用rpc方式调用ws
RPCServiceClient serivceClient = new RPCServiceClient();
Options options = serivceClient.getOptions();
options.setTo(targetEPR);
//这里必须配置SOAPAction=http://www.example.com/OnlineBanking/Login;
//否则就会报“org.apache.axis2.AxisFault:
//The endpoint reference (EPR) for the Operation not found is
//http://localhost:8088/ums/services/OnlineBankingService and the WSA Action = urn:anonOutInOp”
//的错误.
//而且必须跟WSDL里面定义的一致
// <wsdl:operation name="getPrice">
// <soap:operation soapAction="urn:getPrice" style="document"/>
//options.setAction("urn:sayHello");
//指定要调用sayHello方法及wsdl文件的命名空间
//targetNamespace="http://ws.apache.org/axis2"
QName opAddEntry = new QName(NS,"sayHello");
//调用sayHello方法
//param1:方法,param2:方法入参 Object[],param3:返回值类型 Class[]
System.out.println(serivceClient.invokeBlocking(opAddEntry, new Object[]{"wanghc"},new Class[]{String.class})[0]);
Thread.sleep(1000);
//getprice方法代码
//options.setAction("urn:getPrice");
opAddEntry = new QName(NS,"gerPrice");
System.out.println(serivceClient.invokeBlocking(opAddEntry, new Object[]{},new Class[]{int.class})[0]);
}
}
开始报错
2011-05-16 17:20:55,043 - < Parameter add on object org.apache.axis2.description.ParameterIncludeImpl@113ff65>
2011-05-16 17:20:55,043 - < Key =password>
2011-05-16 17:20:55,043 - < Value =axis2>
2011-05-16 17:20:55,043 - < Value Class = java.lang.String>
2011-05-16 17:20:55,043 - < Value Classloader = null>
2011-05-16 17:20:55,043 - <Call Stack = DEBUG_FRAME = org.apache.axis2.util.JavaUtils.callStackToString(JavaUtils.java:564)
DEBUG_FRAME = org.apache.axis2.description.ParameterIncludeImpl.debugParameterAdd(ParameterIncludeImpl.java:315)
DEBUG_FRAME = org.apache.axis2.description.ParameterIncludeImpl.addParameter(ParameterIncludeImpl.java:106)
.....
我用的axis2是1.4.1版本的我把他所有的jar都放到buidlpath中
后面在网上找了下,是包的问题
把包改成下面的就行了(我把jar放到我的资源中了)
后面就用问题
Exception in thread "main" org.apache.axis2.AxisFault: The endpoint reference (EPR) for the Operation not found is http://localhost:8080/axis2/services/SimpleService and the WSA Action = urn:anonOutInOp
网上查了下发现那个
少了这句
options.setAction("urn:getPrice");
"urn:getPrice" 这个是wsdl中的
wsdl:binding下的