I am trying to send SMS message using a GSM modem in ASP.NET. I tried using this code in my .NET application it works. But when I ran it in a Web app. Doesnt work.
I am using GSMComm library.
Whenever Im tryin to send a message I get this error:
Exception thrown:
'System.NullReferenceException' in App_Web_pqr1nllj.dll
Here is my code:
GsmCommMain comm;
protected void Connect_Click(object sender, EventArgs e)
{
if(ComPort.Text == "")
{
return;
}
comm = new GsmCommMain(ComPort.Text, 9600, 150);
bool retry;
do
{
retry = false;
try
{
comm.Open();
string message = "Success!";
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<script type = 'text/javascript'>");
sb.Append("window.onload = function(){");
sb.Append("alert('");
sb.Append(message);
sb.Append("')};");
sb.Append("</script>");
ClientScript.RegisterStartupScript(this.GetType(), "alert", sb.ToString());
retry = true;
}
catch(GsmComm.GsmCommunication.CommException)
{
string message = "Gsm not available";
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<script type = 'text/javascript'>");
sb.Append("window.onload = function(){");
sb.Append("alert('");
sb.Append(message);
sb.Append("')};");
sb.Append("</script>");
ClientScript.RegisterStartupScript(this.GetType(), "alert", sb.ToString());
return;
}
} while(retry);
}
protected void Send_Click(object sender, EventArgs e)
{
try
{
SmsSubmitPdu pdu;
//byte dcs = (byte)DataCodingScheme.GeneralCoding.Alpha7BitDefault;
pdu = new SmsSubmitPdu(Message.Text, Number.Text);
comm.SendMessage(pdu);
}
catch(Exception)
{
string message = "Sending failed!";
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<script type = 'text/javascript'>");
sb.Append("window.onload = function(){");
sb.Append("alert('");
sb.Append(message);
sb.Append("')};");
sb.Append("</script>");
ClientScript.RegisterStartupScript(this.GetType(), "alert", sb.ToString());
}
}
When I click the "send button", it gives an error in the debug panel in my visual studio.
How can I fix this error?