ASP.NET: Send SMS using asp.net MVC using ASPSMS

Standard

Sending SMS from asp.net mvc application using ASPSMS service is pretty easy.

Benefits

  • Text SMS, Binary SMS, Unicode SMS etc.
  • Concatenated SMS (up to 9 SMS linked together as one SMS, up to 1377 characters)
  • Bulk SMS functionality
  • Personalized bulk SMS deliveries
  • Define an originator for each sent SMS
  • Realtime SMS delivery notifications
  • Intelligent SMS routing which provides best possible delivery quality
  • ASPTOKEN, innovative two-factor authentication method
  • ASPSMS offers the most extensive SMS roaming (over 200 countries and 900 mobile networks)

Get Free Trial Account:

2016-09-06-12_47_01-aspsms-com-test-credits

2016-09-06-12_47_14-aspsms-com-test-credits

  • Create trial account signing in to website using Email and Password. You will receive USERKEY and Sender Approved Number 

Code:

       public String TestASPSMS(SmsModel obj)
       {
            const string url = "https://webservice.aspsms.com/aspsmsx2.asmx";
            const string action = "https://webservice.aspsms.com/aspsmsx2.asmx/SendSimpleTextSMS";
 
            XmlDocument soapEnvelopeXml = CreateSoapEnvelopeForASPSMS(obj);
            HttpWebRequest webRequest = CreateWebRequest(url, action);
 
            InsertSoapEnvelopeIntoWebRequest(soapEnvelopeXml, webRequest);
 
            string result;
            using (WebResponse response = webRequest.GetResponse())
            {
                using (StreamReader rd = new StreamReader(response.GetResponseStream()))
                {
                    result = rd.ReadToEnd();
                }
            }
            return result;
        }
 
        private static HttpWebRequest CreateWebRequest(string url, string action)
        {
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
            webRequest.Headers.Add("SOAPAction", action);
            webRequest.ContentType = "text/xml;charset=\"utf-8\"";
            webRequest.Accept = "text/xml";
            webRequest.Method = "POST";
            return webRequest;
        }
 
        private static XmlDocument CreateSoapEnvelopeForASPSMS(SmsModel obj)
        {
            obj.Sender = "Sender_Approved_Number";
            XmlDocument soapEnvelopeXml = new XmlDocument();
            soapEnvelopeXml.LoadXml(@"<?xml version=""1.0"" encoding=""utf-8""?>
                    <soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
                    <soap:Body>
                    <SendSimpleTextSMS  xmlns=""https://webservice.aspsms.com/aspsmsx2.asmx"">
                    <UserKey>userkey</UserKey>
                    <Password>password</Password>
                    <Recipients>" + obj.Reciever + "</Recipients>" +
                    "<Originator>" + obj.Sender + "</Originator>" +
                    "<MessageText>" + obj.Message + "</MessageText>" +
                    "</SendSimpleTextSMS >" +
                    "</soap:Body>" +
                    "</soap:Envelope>");
            return soapEnvelopeXml;
        }
 
        private static void InsertSoapEnvelopeIntoWebRequest(XmlDocument soapEnvelopeXml, HttpWebRequest webRequest)
        {
            using (Stream stream = webRequest.GetRequestStream())
            {
                soapEnvelopeXml.Save(stream);
            }
        }

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s