java客户端调用webService

本文介绍了在调用WebService接口过程中遇到的问题及解决方案。通过对比两种不同的调用方式,阐述了如何正确设置参数名称和目标命名空间,以实现稳定的数据交互。

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

啥也不想说,以前使用的方法突然不行了。各种网搜(记得别忘记到jar包哦:axis.jar)

看代码,第一种方式,也就是以前的方式:

改方式不用表名参数名称

 1 public static String invokeStrTypeInMethod(String wsdl, String dataStr,String methodName) throws ServiceException, RemoteException{
 2         Service service = new Service();
 3         Call call = null;
 4         String result = null; 
 5         
 6         call = (Call) service.createCall();
 7 //        call.setOption("soap.wsdl_cache_enabled", "0");
 8         call.setTargetEndpointAddress(wsdl);
 9         call.setOperationName(methodName);//WSDL里面描述的接口名称
10         call.addParameter("in", org.apache.axis.encoding.XMLType.XSD_DATE,
11                 javax.xml.rpc.ParameterMode.IN);//接口的参数
12         call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);//设置返回类型 
13         result = (String)call.invoke(new Object[]{dataStr});
14         return result;
15     }

目前遇见的情况是:part scanPay was not recognized(Does it exist in service WSDL?)

网搜过后,换了一种方式访问:

 1 public static String invokeHuanXunPayMethod(String huanXunEndpoint, String datas, String methodName,String methodParameterName) throws ServiceException, RemoteException {
 2         Service service = new Service();
 3         Call call = null;
 4         String result = null; 
 5         
 6         call = (Call) service.createCall();
 7         call.setTargetEndpointAddress(huanXunEndpoint);
 8         call.setOperationName(new QName(访问wsdl地址后的targetNamespace, methodName));
 9 //        call.setOperationName("insertProdutc");//WSDL里面描述的接口名称
10         call.addParameter(methodParameterName, org.apache.axis.encoding.XMLType.XSD_STRING,
11                 javax.xml.rpc.ParameterMode.IN);//接口的参数
12         call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);//设置返回类型 
13 //        String result = WebServicesUtils.invokeStrTypeInMethod(endpoint, dataStr, "insertProdutc");
14 //        System.out.println(dataStr);
15         result = (String)call.invoke(new Object[]{datas});
16         return result;
17     }

这种方式是要指定明确的域名,以及方法参数名称,好了;欢迎各位丢板砖提意见,谢谢!!

转载于:https://www.cnblogs.com/cunkouzh/p/6743637.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值