axis2 java.net.url_axis2调用.net写的webservice接口实现,指定参数名
参考文章:https://blog.csdn.net/wangyu2016/article/details/76022928
使用axis2调用调用.net写的webservice接口时出现参数无法传递给接口的问题,找了很多资料,一下是找到可以实现的方法
正确代码为:
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import java.rmi.RemoteException;
public class Axis2Test
{
public static void main(String[] args) throws RemoteException {
test();
}
public static void test() throws AxisFault {
try {
String url = "目标URL";
Options options = new Options();
EndpointReference targetEPR = new EndpointReference(url);
options.setTo(targetEPR);
options.setAction("目标的TargetNameSpace"+"调用的方法名");//需要加上这条语句
ServiceClient sender = new ServiceClient();
sender.setOptions(options);
OMFactory fac = OMAbstractFactory.getOMFactory();
String tns = "目标的TargetNameSpace";
OMNamespace omNs = fac.createOMNamespace(tns, "");
OMElement method = fac.createOMElement("调用的方法名", omNs);
OMElement symbol = fac.createOMElement("参数名", omNs);
symbol.addChild(fac.createOMText(symbol, "参数值"));
method.addChild(symbol);
method.build();
OMElement result = sender.sendReceive(method);
System.out.println(result);
} catch (AxisFault axisFault) {
axisFault.printStackTrace();
}
}
}
详细步骤:
第一步 添加axis2相关的jar包,我使用maven管理jar包
maven 中pom.xml配置如下:
1.3
1.2.5
1.1.1
1.6.2
1.4.5
3.1
3.0
backport-util-concurrent
backport-util-concurrent
${backport-util-concurrent.version}
commons-httpclient
commons-httpclient
${commons-httpclient.version}
org.apache.ws.commons.schema
XmlSchema
${XmlSchema.version}
wsdl4j
wsdl4j
${wsdl4j.version}
commons-logging
commons-logging
${commons-logging.version}
org.apache.ws.commons.axiom
axiom
${axiom.version}
org.apache.axis2
axis2
${axis2.version}
第二步:使用axis方法调用webservice接口
/**
* 测试 退费处理
* @return
*/
public static void refundHandle_test2() {
try {
//读取配置文件中的ur、命名空间、方法名
PropertiesUtil propUtil = new PropertiesUtil("RefundInf.properties");
Properties pros = propUtil.getProperties();
String webServiceURL = pros.getProperty("webServiceURL");
String actionStr = pros.getProperty("actionStr");
String actionName = pros.getProperty("actionName");
String url = webServiceURL;
Options options = new Options();
EndpointReference targetEPR = new EndpointReference(url);
options.setTo(targetEPR);
options.setAction(actionStr+actionName);//需要加上这条语句
ServiceClient sender = new ServiceClient();
sender.setOptions(options);
OMFactory fac = OMAbstractFactory.getOMFactory();
String tns = actionStr;
OMNamespace omNs = fac.createOMNamespace(tns, "");
OMElement method = fac.createOMElement(actionName, omNs);
OMElement symbol = fac.createOMElement("json", omNs);
//json字符串参数组装
JsonObject obj = new JsonObject();
obj.addProperty("OrgBillNo", "201806150939108");
obj.addProperty("transaction_id", "");
obj.addProperty("HisRefundNo", "2018061510081109");
obj.addProperty("total_fee", "0.10");
obj.addProperty("Amount", "0.01");
obj.addProperty("payChannel", "zfb");
String aaa = obj.toString();
symbol.addChild(fac.createOMText(symbol,aaa));//为指定的参数名传入参数值
method.addChild(symbol);
method.build();
OMElement result = sender.sendReceive(method);
System.out.println(result);
} catch (AxisFault axisFault) {
axisFault.printStackTrace();
}
}
这样就可以把参数传递给.net的webservice服务了,,正确获取接口返回信息
另外备注一下,完成这个任务后,我会尝试用axis1和HttpClient试试调用接口的方法
axis2 java.net.url_axis2调用.net写的webservice接口实现,指定参数名相关推荐
- java使用axis调用.net发布的webservice接口返回对象类型
本人在java中axis-1.4 调用 .net发布的webService接口 有问题欢迎各路大神讨论 !!! 1.1 基本类型 1.2 对象类型 1.3复杂对象类型(对象类中嵌套对象类) 返回基本类 ...
- android wsdl封装,在Android中调用C#写的WebService(附源代码)
由于项目中要使用Android调用C#写的WebService,于是便有了这篇文章.在学习的过程中,发现在C#中直接调用WebService方便得多,直接添加一个引用,便可以直接使用将WebServi ...
- SpringBoot调用.asmx后缀的webservice接口
目录 一.简介 二.示例 一.简介 最近在项目中,在与其他公司做对接中需要回调一个对方的接口,根据对方提供的接口地址, 发现是webservice的接口,而且接口后缀名为.asmx,因为现在webse ...
- java 调用.net webservice axis2_java利用axis2调用.net写的webservice,传递自定义的实体类参数...
利用axis2可以很方便的自动生成客户端代码,同时对复杂参数类型的传递也很方便,本文的服务端以.net开发,有一个自定义的实体类作为参数,客户端用java,简单介绍一下利用axis2的wsdl2jav ...
- java调用asmx接口_java调用.net写的webserver接口(.asmx后缀)
JAVA用这种方式调用webservice,需要注意的地方: 1. 服务器未能识别 HTTP 标头 SOAPAction 的值: 症状一: Web Service + ASP.NET 应用程序部署到服 ...
- Java调用.net开发的webService接口
若一个webservice接口是以.asmx格式来结尾的话,则表明该接口是.net开发的接口 例如:http://www.webxml.com.cn/WebServices/TranslatorWeb ...
- delphi 调用 c# 写的webservice
调用helloWorld的返回值是正确的,调用add的时候,传入(1,2)时,返回值却为0,不知什么原因,这个问题困惑了很久,请高手们指教~ 以下是源码 //c#写的webservice的源码 [We ...
- android开发接口调用,Android开发中webService接口调用示例
代码示例: package com.study.ws; import java.io.IOException; import org.ksoap2.SoapEnvelope; import org.k ...
- java xfire指定参数名_xfire中自定义参数名
近期在做多个应用交互系统,其中数据交互采用了webservice的方式,说到webservice项目中不得不用到xfire这个框架,有了它我们几乎不用写代码,就可以很快速的创建自己的webservic ...
最新文章
- [转]android selector 背景选择器
- HTTP相关知识 - 1
- 005_MySQL数据类型
- 原生APP与web APP的区别
- 确认类是否可以在运行期使用
- 前端学习(1923)vue之电商管理系统电商系统之说明角色要完成的功能
- PyTorch实战福利从入门到精通之四——卷积神经网络CIFAR-10图像分类
- javascript java map_javascript实现java的map对象,js实现new map()
- [算法] 循环有序数组查找递归实现
- web字体设置成平方字体_Web字体正确完成
- 关于PLC手册中的源型和漏型
- VSCode SSH 远程连接
- sublime text 提示error while loading pyvb binvry:exit code3 try tomanually install pyvb的处理方法
- java在win8闪退_win8.1应用闪退
- 解决click在ios反应慢的问题
- CISSP第二章 信息安全治理与风险管理
- 查询一年1、1-2月、1-3~一直到1-12月
- 黄聪:清理微信浏览网站的缓存,Cookie
- DOCSIS 3.1 MMM--3.MAP
- maven自带clean_Maven生命周期(示例代码)
热门文章
- netcore5开发Android,那些鼓吹国内首个.NET 5框架的,该醒醒了!
- mysql 超时_为MySQL设置查询超时
- c语言printf输出中文报错,printf输出中文后还带有数字是怎么回事?
- php 微信支付退款接口开发,微信支付退款功能开发
- java 面向对象继承的思想_Java面向对象思想!
- 为别人着想的表达才是最好的表达
- androidStudio导入库文件
- java分布式事务 实例_spring整合atomikos实现分布式事务的方法示例
- 基于JAVA+SpringMVC+MYSQL的记账管理系统
- 深入理解Spring Redis的使用 (九)、通过Redis 实现 分布式锁 的 BUG,以及和数据库加锁的性能测试...