You are on page 1of 3

http://www.codeproject.

com/Articles/29106/Migrate-MySQL-to-Microsoft-SQL-Server
public class SendMSG
{
string username;
string password;
string msgSender;
string mobileNo;
string message;
public SendMSG(string username, string password, string msgSender)
{
this.username = username;
this.password = password;
this.msgSender = msgSender;
}
//Public Sub New(ByVal username As String, ByVal password As String, ByVal msgSender As String,
ByVal mobileNo As String, ByVal message As String)
// Me.username = username
// Me.password = password
// Me.msgSender = msgSender
// Me.mobileNo = mobileNo
// Me.message = message
// SendMessage()
//End Sub
//public void SendMSG()
//{
// //Create ViaNettSMS object with username and password
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//

//Declare Result object returned by the SendSMS function


Result result = new Result();
try
{
//Send SMS through HTTP API
result = SendSMS(destinationaddr: mobileNo, message: message);
//Show Send SMS response
if (result.Success)
{
Debug.WriteLine("Message successfully sent");
}
else
{
Debug.WriteLine("Received error: " + result.ErrorCode + " " + result.ErrorMessage);
}
}
catch (System.Net.WebException ex)
{
//Catch error occurred while connecting to server.
Debug.WriteLine(ex.Message);
}

//}
public Result SendSMS(string destinationaddr, string message)
{

string url = null;


string serverResult = null;
Result result = null;
//h
//ttp://admarksms.org/SMSAPI.jsp?
username=chandukaka2&password=chandukaka2&sendername=chanduka&mobileno=9960445009&
message=Hello
//url = "http://admarksms.org/SMSAPI.jsp?" & _
//
"&username=" & HttpUtility.UrlEncode(username) & _
//
"&password=" & HttpUtility.UrlEncode(password) & _
//
"&sendername=" & HttpUtility.UrlEncode(msgSender) & _
//
"&mobileno=" & HttpUtility.UrlEncode(destinationaddr) & _
//
"&message=" & HttpUtility.UrlEncode(message)
//Sample message for mVayoo API
//http://api.mVaayoo.com/mvaayooapi/MessageCompose?
user=gvshah@chandukakasaraf.com:Cspl123&senderID=TEST
//SMS&receipientno=9405996357&dcs=0&msgtxt=This is Test message&state=4
// http://map-alerts.smsalerts.biz//api/web2sms.php?
workingkey=419zwicbi3v3v3aee6w&to=Mobileno&sender=PHINIX&message=<MESSAGE>
// url = "http://api.mVaayoo.com/mvaayooapi/MessageCompose?" + "user=" +
HttpUtility.UrlEncode(username)+":"+HttpUtility.UrlEncode(password) + "&senderID=" +
HttpUtility.UrlEncode(msgSender) + "&receipientno=" + HttpUtility.UrlEncode(destinationaddr) +
"&dcs=0&msgtxt=" + HttpUtility.UrlEncode(message) + "&state=4";
// url = "http://map-alerts.smsalerts.biz//api/web2sms.php?
workingkey=419zwicbi3v3v3aee6w&to=" + HttpUtility.UrlEncode(destinationaddr) +
"&sender=PHINIX&message="+HttpUtility.UrlEncode(message);
serverResult = DownloadString(url);
result = ParseServerResult(serverResult);
return result;
}
/// <summary>
/// Downloads the URL from the server, and returns the response as string.
/// </summary>
/// <param name="URL"></param>
/// <returns>Returns the http/xml response as string</returns>
/// <exception cref="WebException">WebException is thrown if there is a connection
problem.</exception>
private string DownloadString(string URL)
{
//Create WebClient instanse.
using (System.Net.WebClient wlc = new System.Net.WebClient())
{
try
{
//Download and return the xml response
return wlc.DownloadString(URL);
}
catch (WebException ex)
{
//Failed to connect to server. Throw an exception with a customized text.
throw new WebException("Error occurred while connecting to server. " + ex.Message, ex);
}

/// <summary>
/// Parses the XML code and returns a Result object.
/// </summary>
/// <param name="ServerResult">XML data from a request through HTTP API.</param>
/// <returns>Returns a Result object with the parsed data.</returns>
private Result ParseServerResult(string ServerResult)
{
System.Xml.XmlDocument xDoc = new System.Xml.XmlDocument();
// Dim ack As System.Xml.XmlNode
Result result = new Result();
//xDoc.LoadXml(ServerResult)
//changes for mVayoo API
//If ServerResult.ToLower.Contains("success") Then
//if (ServerResult.ToLower.Contains("status=0"))
//{
// result.Success = true;
//}
//else
//{
// result.Success = false;
//}
//ack = xDoc.GetElementsByTagName("ack").Item(0)
//result.ErrorCode = CInt(ack.Attributes("errorcode").Value)
//result.ErrorMessage = ack.InnerText
//result.Success = (result.ErrorCode = 0)
return result;

}
public class Result
{
public bool Success;
public int ErrorCode;
public string ErrorMessage;
}
}

You might also like