//测试环境的接口地址
public static String URL = "http://xxx.xxx.xx.xxx:xxxx/CRM/WebService/WebService1.asmx";
//正式环境的接口地址
// public static String URL = "http:// *** /CRM/WebService/WebService1.asmx";
public static String TOKEN = "JSICCHDDSJSONNVVHADSFB9836NASNDFKJVVVACCXX";
/**
* 调用webservice.asmx接口
* @param ctx
* @param method 需要调用的方法
* @param json 传递的参数
* @throws BOSException
* @throws EASBizException
*/
public void callWebserviceASMX(Context ctx, UserInfo userinfo, String method, String json) throws EASBizException, BOSException{
InterfaceCallRecordTableInfo info = new InterfaceCallRecordTableInfo();
String result = null;
//获取域名地址,server定义的
String soapaction = "http://tempuri.org/";
Service service = new Service();
try {
//实现Call类
Call call = (Call) service.createCall();
//添加接口地址
call.setTargetEndpointAddress(URL);
// 设置要调用哪个方法
call.setOperationName(new QName(soapaction, method));
//设置传递的值
call.addParameter(new QName(soapaction,"Token"), XMLType.XSD_STRING, ParameterMode.IN);
//设置传递的值
call.addParameter(new QName(soapaction,"json"), XMLType.XSD_STRING, ParameterMode.IN);
//标准的类型
call.setReturnType( XMLType.XSD_STRING);
call.setUseSOAPAction(true);
call.setSOAPActionURI(soapaction+method);
//调用方法并传递参数
result = (String) call.invoke(new Object[]{TOKEN,json});
//识别是否参数有问题
// char[] charArray = result.toCharArray();
// String standard = charArray[13]+"";
// if("t".equals(standard)){
// info.setWhetherToSynchronize(whetherToSynchronize.YES);
// }else if("f".equals(standard)){
// info.setWhetherToSynchronize(whetherToSynchronize.ON);
// }
//给是否同步的判断表示
info.setWhetherToSynchronize(whetherToSynchronize.YES);
} catch (Exception e) {
//接口出现异常给标识
info.setWhetherToSynchronize(whetherToSynchronize.ON);
e.printStackTrace();
} finally{
//生成ID
info.setId(BOSUuid.create("D3E4E413"));
//设置当前登录人
info.setFounder(userinfo.getId().toString());
//创建时间
info.setCreationTime(new Date());
//接口反馈信息
info.setFeedback(result);
//给接口传递的数据信息
info.setTransmitInformation(json);
//判断是UI界面的保存方式还是后台的保存方式
if(ctx!=null){
//设置是哪个接口传递的
info.setInterfaceType(interfaceType.BILLING);
//保存数据
InterfaceCallRecordTableFactory.getLocalInstance(ctx).addnew(info);
}else{
//设置是那个接口传递的
info.setInterfaceType(interfaceType.RECEIPT);
//保存数据
InterfaceCallRecordTableFactory.getRemoteInstance().addnew(info);
}
}
}