.NET Sample: GetCustomerInfo

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Net.Mail;

namespace smsBasicSample
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                string userName = "testuser";
                string password= "password";
                string keyword = "keyword";
                string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(userName+":"+password+":"+keyword));

                string method = "getcustomerinfo";
                string postvars = "phone_number=9993331212";
                // the smsResponse will be an object, but the smsResponse.payload will be the XML data 
                // Use LINQ to SQL or any other XML parser (your preference)
                var smsResponse = SMSClient(credentials, method, postvars);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }

        /// 
        /// Simple Client to Connect to SMS Service
        /// 
        /// 
        /// 
        /// 
        /// 
        static SMSResponse SMSClient(string credentials, string method, string postvars)
        {
             SMSResponse smsr = new SMSResponse();
            try
            {
                WebClient webClient = new WebClient();
                // webClient.Headers.Add("X-Dispatch", "D419FEC9-D98D-440E-9676-DFAB46861114");
                webClient.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
                webClient.Headers[HttpRequestHeader.Authorization] = "Basic " + credentials;
                string xml = webClient.UploadString("https://restapi.crmtext.com/smapi/rest/" + method, "POST", postvars);
              
                smsr.status = "pass";
                smsr.payload = xml;
               
            }
            catch (Exception ex)
            {
                smsr.status = "error";
                smsr.payload = ex.ToString();
            }
              return smsr;  
        }
    }
    /// 
    /// Simple Object to stuff status and response into
    /// 
    public class SMSResponse
    {
       public  string status { get; set; }
       public string payload { get; set; }
    }
}		

.NET Sample: SetCallback

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CTG.Core;
using System.Net;
using System.Xml;
using System.Xml.Serialization;
using System.Text;
using System.IO;

namespace CTG.Web
{
    public partial class SetCallbackURL : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            //Create Web Request 
            string url = "https://restapi.crmtext.com/smapi/rest?";
            WebRequest request = WebRequest.Create(url);

            // Add Timeout to the request
            request.Timeout = ((1000 * 60) * 30);

            // Create Authentication String and add to the request header
            string authInfo = Username.Text + ":" + Password.Text + ":" + Keyword.Text;
            byte[] bytesToEncode = Encoding.UTF8.GetBytes(authInfo);
            string encodedText = Convert.ToBase64String(bytesToEncode);
            request.Headers["Authorization"] = "Basic " + encodedText;

            //Identify the method to be used. in this case we use post message 
            request.Method = "POST";

            string postMessage = "method=setcallback&callback=" + Server.UrlEncode(URL.Text);

            //Instantiate buffer and encoding type . 
            byte[] buffer = Encoding.GetEncoding("UTF-8").GetBytes(postMessage);

            //Set the content type and content length in the header 
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = buffer.Length;

            //Set the stream and write the buffer 
            Stream reqstr = request.GetRequestStream();
            reqstr.Write(buffer, 0, buffer.Length);
            reqstr.Close();

            //get the response .
            WebResponse response = request.GetResponse();
            Stream dataStream = response.GetResponseStream();
            // Open the stream using a StreamReader for easy access.
            StreamReader reader = new StreamReader(dataStream);
            // Read the content.
            string responseFromServer = reader.ReadToEnd();


            Response responseBack = GetResponseObject(responseFromServer);

        }

        private Response GetResponseObject(string xmlResponse)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Response));
            Response result = null;
            using (TextReader reader = new StringReader(xmlResponse))
            {
                result = (Response)serializer.Deserialize(reader);
            }
            return result;
        }


        [XmlRoot("response")]
        public class Response
        {
            [XmlAttribute("op")]
            public string OP { get; set; }

            [XmlAttribute("status")]
            public string Status { get; set; }

            [XmlAttribute("message")]
            public string Message { get; set; }

        }
    }
}		

.Net Sample: Web Hook Mobile Originated Capture Set-Up

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CTG.Core;
using System.Text;

namespace CTG.Web
{
    public partial class CRMCallback : System.Web.UI.Page
    {
        #region CRM Request Variables

        private string _custID;
        private string _message;
        private string _keyword;
        private string _mobileNum;
        private string _OptInStatus;
        private string _timeStamp;
        private string _subacct;
        private string _custName;
        private string _msgID;
        private string _subacct_name;
        private string _mms;

        protected string custID
        {
            get { return _custID; }
            set { _custID = value; }
        }

        protected string message
        {
            get { return _message; }
            set { _message = value; }
        }

        protected string keyword
        {
            get { return _keyword;  }
            set { _keyword = value; }
        }

        protected string mobileNum
        {
            get { return _mobileNum; }
            set { _mobileNum = value; }
        }

        protected string OptInStatus
        {
            get { return _OptInStatus; }
            set { _OptInStatus = value; }
        }

        protected string timeStamp
        {
            get { return _timeStamp; }
            set { _timeStamp = value; }
        }

        protected string subacct
        {
            get { return _subacct; }
            set { _subacct = value; }
        }

        protected string custName
        {
            get { return _custName; }
            set { _custName = value; }
        }

        protected string msgID
        {
            get { return _msgID; }
            set { _msgID = value; }
        }

        protected string subacct_name
        {
            get { return _subacct_name; }
            set { _subacct_name = value; }
        }

        protected string mms
        {
            get { return _mms; }
            set { _mms = value; }
        }

        #endregion

        #region Events
        protected void Page_Load(object sender, EventArgs e)
        {
            //Write to log to debug issues
            WriteToLog();

            //Find request objects sent by CRM and assign to variables
            AssignVariables();

            //Process the request and update our DB
            ProcessRequest();
        }
        #endregion Events

        #region Methods
        private void WriteToLog()
        {
            //Create a stringbuilder object to hold our log item
            StringBuilder sb = new StringBuilder();
            sb.Append("Form: ");
            //Iterate through form object and append to sb
            foreach (string key in Request.Form.Keys)
            {
                sb.Append(key + " = " + Request.Form[key] + ";");
            }

            sb.Append("QueryString: ");
            //Iterate through our querystring object and append to sb
            foreach (string key in Request.QueryString.Keys)
            {
                sb.Append(key + " = " + Request.QueryString[key] + ";");
            }

            //Assign our results to our new log object
            UpdateLog(sb.ToString());
        }

        private void ProcessRequest()
        {
            try
            {
                //Create a property and mobileuser object to update our db 
                Property property = null;
                MobileUser mobileUser = null;
                //Get our status type based upon message contents
                int StatusType = GetStatusType();

                UpdateLog("Grabbed status type = " + StatusType);

                if (subacct_name != string.Empty)
                {
                    //Get property based on sub account name
                    property = GetPropertyByStoreName(subacct_name);
                    UpdateLog("Grabbed property = " + property.Id);
                    if (property != null && mobileNum != string.Empty)
                    {
                        //Get mobile user based on property and mobile num
                        mobileUser = GetMobileUserByPhoneNumber(property.Id, mobileNum);
                        UpdateLog("Grabbed mobile user = " + mobileUser.Id);
                        if (mobileUser != null && StatusType > 0)
                        {
                            //Update our db with mobile number status
                            UpdateMobileUserStatus(mobileUser.Id, StatusType);
                            UpdateLog("Updated status successfully!");
                        }
                    }
                }
            }
            catch(Exception ex)
            {
                //If there was an error, log it here
                UpdateLog(ex.Message);
            }

        }

        private int GetStatusType()
        {
            //Get mobile number status based on message contents
            int returnValue = 0;
            UpdateLog("Parsing message: (" + message.ToLower() + ") Opt in status: (" + OptInStatus + ")");
            switch( message.ToLower())
            {
                case "yes":
                    returnValue = 2;
                    break;
                case "stop": 
                case "quit":
                    returnValue = 3;
                    break;
            }
            return returnValue;
        }

        //Retrieve our property based upon the store name in the request object
        private Property GetPropertyByStoreName(string storeName)
        {
            return PropertyProvider.SharedInstance.SelectPropertyByStoreName(storeName);
        }

        //Retrieve our mobile user based on the property id and phone number
        private MobileUser GetMobileUserByPhoneNumber( int propertyId, string phoneNumber )
        {
            return MobileUserProvider.SharedInstance.SelectMobileUserByPhoneNumber(propertyId, phoneNumber);
        }

        //Update the mobile users status based upon the message contents
        private void UpdateMobileUserStatus(int mobileUserId, int status)
        {
            MobileUserProvider.SharedInstance.UpsertMobileUserStatus(status, mobileUserId);
        }
        
        //Assign variables based on the incoming request object
        private void AssignVariables()
        {
            try
            {
                custID = VariableOut("CustID");
                message = VariableOut("message");
                keyword = VariableOut("keyword");
                mobileNum = VariableOut("mobileNum");
                OptInStatus = VariableOut("optInStatus");
                timeStamp = VariableOut("timeStamp");
                subacct = VariableOut("subacct");
                custName = VariableOut("custName");
                msgID = VariableOut("msgID");
                subacct_name = VariableOut("subacct_name");
                mms = VariableOut("mms");
            }
            catch(Exception ex)
            {
                //If there's an error here, log it
                UpdateLog(ex.Message);
            }
        }

        //Make sure the object exists and set accordingly
        private string VariableOut(string requestObject)
        {
            string returnValue = string.Empty;
            try
            {
                if (Request[requestObject] != null) returnValue = (Server.UrlDecode(Request[requestObject])).Trim();                
            }
            catch (Exception ex)
            {
                //If there's an error here, log it
                UpdateLog(ex.Message);
            }
            return returnValue;
        }

        private void UpdateLog(string ErrorDescription)
        {
            SendLog log = new SendLog();
            log.ErrorCode = "Inbound CRM";
            log.ErrorDescription = ErrorDescription;

            SendLogProvider.SharedInstance.UpdateSendErrorLog(log);
        }
        #endregion Methods
    }
}