java调用 .net 接口_Java测试调用.net 接口服务

packagecom.karros.test;importjava.util.HashMap;importjava.util.Map;importjavax.xml.namespace.QName;importorg.apache.axis.client.Call;importorg.apache.commons.lang.StringUtils;importorg.apache.commons.logging.Log;importorg.apache.commons.logging.LogFactory;public classTestWsdl {protected final Log logger =LogFactory.getLog(getClass());public static void main(String[] args) throwsException {

Map paramMap = new HashMap();

paramMap.put("syncTime", "20200401");

Map resultMap = new HashMap();

TestWsdl aa= newTestWsdl();

resultMap=aa.getWebService(paramMap);

System.out.println(resultMap);

}//@Value("${weixin_sign_url}")//private String endpoint;//#微信签到云平台接口地址//weixin_sign_url=http://10.182.5.173:1111/Service/WXQDService.asmx

public String endpoint = "http://10.182.5.96:102/Service/ORGService.asmx";public Map getWebService(Map paramMap) throwsException {

logger.debug("获取接口开始...");

Map resultMap = new HashMap();

resultMap.put("success", true);try{

String syncTime= (String) paramMap.get("syncTime");if (StringUtils.isBlank(syncTime)) { //20200401

resultMap.put("success", false);returnresultMap;

}else{//创建一个服务(service)调用(call)

org.apache.axis.client.Service service = neworg.apache.axis.client.Service();

Call call= (Call) service.createCall();//通过service创建call对象//设置service所在URL

call.setTargetEndpointAddress(newjava.net.URL(endpoint));

call.setOperationName(new QName("http://tempuri.org/", "GetUserList"));//.net 那边的方法 "http://tempuri.org/"这个也要注意Namespace的地址,不带也会报错

call.addParameter(new QName("http://tempuri.org/", "syncTime"), org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);

call.setUseSOAPAction(true);

call.setReturnType(org.apache.axis.encoding.XMLType.SOAP_STRING);//返回参数的类型

call.setSOAPActionURI("http://tempuri.org/GetUserList"); //这个也要注意

String userVo = (String) call.invoke(newObject[] { syncTime });if (StringUtils.isBlank(userVo) || StringUtils.equals("[]", userVo)) {

resultMap.put("success", false);

}else{

resultMap.put("userVo", userVo);

}

}

}catch(Exception e) {

resultMap.put("success", false);

logger.error("获取信息异常", e);

}

logger.debug("获取接口结束...");returnresultMap;

}

}

package com.karros.test;

import java.util.HashMap;import java.util.Map;

import javax.xml.namespace.QName;

import org.apache.axis.client.Call;import org.apache.commons.lang.StringUtils;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;

public class TestWsdl {

protected final Log logger = LogFactory.getLog(getClass());public static void main(String[] args) throws Exception {   Map paramMap = new HashMap();paramMap.put("syncTime", "20200401");Map resultMap = new HashMap();TestWsdl aa = new TestWsdl();resultMap= aa.getWebService(paramMap);System.out.println(resultMap);}

//@Value("${weixin_sign_url}")//private String endpoint;//  #微信签到云平台接口地址// weixin_sign_url=http://10.182.5.173:1111/Service/WXQDService.asmxpublic String endpoint = "http://10.182.5.96:102/Service/ORGService.asmx";public Map getWebService(Map paramMap) throws Exception {logger.debug("获取接口开始...");Map resultMap = new HashMap();resultMap.put("success", true);try {String syncTime = (String) paramMap.get("syncTime");if (StringUtils.isBlank(syncTime)) {//20200401resultMap.put("success", false);return resultMap;} else {// 创建一个服务(service)调用(call)org.apache.axis.client.Service service = new org.apache.axis.client.Service();Call call = (Call) service.createCall();// 通过service创建call对象// 设置service所在URLcall.setTargetEndpointAddress(new java.net.URL(endpoint));

call.setOperationName(new QName("http://tempuri.org/", "GetUserList"));// .net 那边的方法 "http://tempuri.org/"这个也要注意Namespace的地址,不带也会报错call.addParameter(new QName("http://tempuri.org/", "syncTime"), org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);

call.setUseSOAPAction(true);call.setReturnType(org.apache.axis.encoding.XMLType.SOAP_STRING); // 返回参数的类型call.setSOAPActionURI("http://tempuri.org/GetUserList"); // 这个也要注意String userVo = (String) call.invoke(new Object[] { syncTime });if (StringUtils.isBlank(userVo) || StringUtils.equals("[]", userVo)) {resultMap.put("success", false);} else {resultMap.put("userVo", userVo);}}} catch (Exception e) {resultMap.put("success", false);logger.error("获取信息异常", e);}logger.debug("获取接口结束...");return resultMap;}

}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值