使用axis调用webservice
发布时间:2020-12-16 22:21:47 所属栏目:安全 来源:网络整理
导读:span style="font-size:14px;" public static boolean send(String MsgContent,String DestNumber){ boolean res = false; try { // webservice路径 // 这里后面加不加 "?wsdl" 效果都一样的 String endpoint = "http://sms.28inter.com:8080/SmsService/Sms
<span style="font-size:14px;"> public static boolean send(String MsgContent,String DestNumber){ boolean res = false; try { // webservice路径 // 这里后面加不加 "?wsdl" 效果都一样的 String endpoint = "http://sms.28inter.com:8080/SmsService/SmsService.asmx"; // 发送短信接口方法名 String operationName = "SendEx"; String targetNamespace = "http://tempuri.org/"; // 定义service对象 Service service = new Service(); // 创建一个call对象 Call call = (Call) service.createCall(); // 设置目标地址,即webservice路径 call.setTargetEndpointAddress(endpoint); // 设置操作名称,即方法名称 call.setOperationName(new QName(targetNamespace,operationName)); // 设置方法参数 call.addParameter(new QName(targetNamespace,"UserId"),XMLType.XSD_STRING,ParameterMode.IN); call.addParameter(new QName(targetNamespace,"Password"),"MsgContent"),"DestNumber"),"SendTime"),"SubNumber"),"BatchSendID"),"BizType"),ParameterMode.IN); // XMLType.XSD_INT call.addParameter(new QName(targetNamespace,"WapURL"),ParameterMode.IN); /** * 设置返回值类型-由于文档给的是返回一个代理类SendExResp-这个需要用ws工具生成,不然就要手动写, * 故这里设置成org.w3c.dom.Element.class,不然会报org.xml.sax.SAXException: SimpleDeserializer encountered a child element,which is NOT expected错误。 * 注:具体的返回类型,根据对方提供的ws进行设置即可,如:call.setReturnClass(String[].class); */ call.setReturnClass(org.w3c.dom.Element.class); // 解决错误:服务器未能识别 HTTP 头 SOAPAction 的值 call.setUseSOAPAction(true); call.setSOAPActionURI(targetNamespace + operationName); // 调用ws方法 call.invoke(new Object[]{SMS.USERID,SMS.PASSWORD,MsgContent,DestNumber,SMS.SENDTIME,SMS.SUBNUMBER,SMS.BATCHSENDID,SMS.BIZTYPE,SMS.WAPURL}); res = true; } catch (ServiceException e) { res = false; e.printStackTrace(); } catch (RemoteException e) { res = false; e.printStackTrace(); } return res; } 注:上述WSDL里面描述的参数BIZTYPE是int类型的,但传递参数时要传递字符串类型,否则报如下错误: 服务器无法读取请求。 ---> XML 文档(1,841)中有错误。 ---> 输入字符串的格式不正确 </span> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |