第一个webService一些问题

在网上学习看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下的

<wsdl:operation name="getPrice">
<soap:operation soapAction="urn:getPrice" style="document"/>
....
最后就可以成功运行了.


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值