zoukankan      html  css  js  c++  java
  • SoapUI调用Web服务

    msg = string.Empty;
                //string sendAddr, string destAddr, string smContent, int IsNeedreport, DateTime sendTime, int smType
                //Web服务的地址(配置在webConfig)
                //string url = "http://iservice-sit.xx.com/eProxy/Service/WS_SMS/001?wsdl";
                string url = System.Configuration.ConfigurationSettings.AppSettings["SendMsgUrl"];
                if (string.IsNullOrEmpty(url)) {
                    msg = "发送短信的服务地址为空";
                    return false;
                }
                //string user = "EIP_EIP_COMMON";
                //string password = "EIP_EIP_COMMON";
                // string smsIsSecurity=System.Configuration.ConfigurationSettings.AppSettings["SmsIsSecurity"];
    
                //StringBuilder sbStr = new StringBuilder();
                //sbStr.Append("<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sms="http://www.tibco.com/schemas/Service_MAS/Resource/SMSEND.xsd">");
                //sbStr.Append("<soapenv:Header>");
    
                ////如果是管控地址需要添加管控账号和密码
                //// if (smsIsSecurity.Equals("true"))
                //// {
                //sbStr.Append("<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" SOAP-ENV:mustUnderstand="1"><wsse:UsernameToken>");
                //sbStr.AppendFormat("<wsse:Username>{0}</wsse:Username>", user);
                //sbStr.AppendFormat("<wsse:Password>{0}</wsse:Password>", password);
                //sbStr.Append("</wsse:UsernameToken>");
                //sbStr.Append("</wsse:Security>");
                //// }
                //sbStr.Append("</soapenv:Header>");
                //sbStr.Append("<soapenv:Body>");
                //sbStr.Append("<sms:SMSENDRequest>");
                ////1 or more repetitions
                //sbStr.Append("<sms:SMENTITY>");
                //sbStr.AppendFormat("<sms:SENDADDR>{0}</sms:SENDADDR>", sm.SENDADDR);
                //sbStr.AppendFormat("<sms:DESTADDR>{0}</sms:DESTADDR>", sm.DESTADDR);
                //sbStr.AppendFormat("<sms:SM_CONTENT>{0}</sms:SM_CONTENT>", sm.SM_CONTENT);
                //sbStr.AppendFormat("<sms:NEEDREPORT>{0}</sms:NEEDREPORT>", sm.NEEDREPORT);
                //sbStr.AppendFormat("<sms:SENDTIME>{0}</sms:SENDTIME>", GetSendTime(sm.SENDTIME));
                //sbStr.AppendFormat("<sms:SM_TYPE>{0}</sms:SM_TYPE>", sm.SM_TYPE);
                ////sbStr.Append("<sms:SYNC_TIME>2011-11-10T12:00:12</sms:SYNC_TIME>");
                ////sbStr.Append("<sms:CREATED_BY>64379</sms:CREATED_BY>");
                //// sbStr.Append("<sms:CREATION_DATE>2011-11-10T12:12:12</sms:CREATION_DATE>");
                //sbStr.Append("</sms:SMENTITY>");
                //sbStr.Append("</sms:SMSENDRequest>");
                //sbStr.Append("</soapenv:Body>");
                //sbStr.Append("</soapenv:Envelope>");
                string sendXml = string.Format("<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:DefaultNamespace" xmlns:sms="http://www.tibco.com/schemas/Service_MAS/Resource/SMSEND.xsd"><soapenv:Header xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><wsse:Security><wsse:UsernameToken><wsse:Username>{0}</wsse:Username> <wsse:Password>{1}</wsse:Password> </wsse:UsernameToken></wsse:Security></soapenv:Header><soapenv:Body><sms:SMSENDRequest><!--1 or more repetitions:--><sms:SMENTITY><sms:SENDADDR>{2}</sms:SENDADDR><sms:DESTADDR>{3}</sms:DESTADDR><!--Optional:--><sms:SM_CONTENT>{4}</sms:SM_CONTENT><!--Optional:--><sms:NEEDREPORT>{5}</sms:NEEDREPORT><sms:SENDTIME>{6}</sms:SENDTIME><sms:SM_TYPE>{7}</sms:SM_TYPE></sms:SMENTITY></sms:SMSENDRequest></soapenv:Body></soapenv:Envelope>",
                    user,
                    password,
                    sm.SENDADDR,
                    sm.DESTADDR,
                    sm.SM_CONTENT,
                    sm.NEEDREPORT,
                    GetSendTime(sm.SENDTIME),
                    sm.SM_TYPE
                );
                //创建XMLHTTP对象读取WebService数据
                MSXML2.XMLHTTP xmlhttp = new MSXML2.XMLHTTP();
                xmlhttp.open("POST", url, false, null, null);
                xmlhttp.setRequestHeader("SOAPAction", "/Service/intfSendShortMessage-service.serviceagent/intfwsSendShortMessageEndpoint1/SendShortMessageOp");
                xmlhttp.setRequestHeader("Content-Type", "application/soap+xml");
                //xmlhttp.send(sbStr.ToString());
                xmlhttp.send(sendXml);
               
                string result = System.Text.Encoding.UTF8.GetString((byte[])xmlhttp.responseBody);
                xmlhttp.abort();
    
                xmlhttp = null;
                if (result.ToUpper().Contains("<NS0:MESSAGECODE>SUCCESS</NS0:MESSAGECODE>"))//"<ns0:messageCode>success</ns0:messageCode>"
                {
                    return true;
                }
                else
                {
                    //LogHelper.Error("SmsSendError", result);
                    msg = result;
                    return false;
                }
  • 相关阅读:
    代码之美
    一点对互联网的浅薄理解
    angularjs填写表单
    一种通用数据采集的schema定义形式
    maven常用命令
    find which process occupy the PORT
    Mac上安装boost开放环境
    codeforces 581B Luxurious Houses
    codeforces 599A Patrick and Shopping
    codeforces 597A Divisibility
  • 原文地址:https://www.cnblogs.com/yomho/p/3713314.html
Copyright © 2011-2022 走看看