Textmagic with asp.net c# SMS API

1,425 views
Skip to first unread message

levin

unread,
Sep 19, 2011, 4:01:10 AM9/19/11
to TextMagic SMS Gateway API
Hi there,

Thanks so much for your C# SMS API i found on
http://code.google.com/p/textmagic-c-sharp-wrapper-class-library/

I am facing some issues. I am trying out the SMS API of textmagic with
my asp.net application.

I signed up to a trial account with textmagic to test my codes. So far
i can get my application to send out an sms using these codes.

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net;

namespace Fruits
{
public partial class WebForm15 : System.Web.UI.Page
{

TextMagicServices.TextMagicMessageService TMS;

protected void Page_Load(object sender, EventArgs e)
{
string user = "username";
string pass = "password";
string strMessage = "testing message";
string strPhone = "61423871777";
//initialize the Service
TMS = new TextMagicServices.TextMagicMessageService(user,
pass);
// to send message to single phone
TextMagicServices.SentMessage objSentMessage = new
TextMagicServices.SentMessage();
objSentMessage = TMS.send(strMessage, strPhone);
}


}
}

However i would like to know if someone can point me in the direction
of how write the code for receiving smses from my asp.net application
page? I read the developer help SMS API guide but i am not really sure
how to do it.

I would greatly appreciate some help. Thanks so much :)

Aleksey Ermakov

unread,
Sep 19, 2011, 4:16:00 AM9/19/11
to TextMagic SMS Gateway API
Hello,
have you tried to use TMS.receive(long lastRecievedId) method? It
should return all inbound messages having id > lastRecievedId.

On Sep 19, 3:01 pm, levin <levin...@gmail.com> wrote:
> Hi there,
>
> Thanks so much for your C# SMS API i found onhttp://code.google.com/p/textmagic-c-sharp-wrapper-class-library/

levin

unread,
Sep 19, 2011, 6:42:25 AM9/19/11
to TextMagic SMS Gateway API
Hi there,

Thanks so much for the prompt reply. However i don't really know how
to write the full codes to make it work.

Do i have to define any object to use the TMS.receive(long
lastRecievedId) method?

With what you told me, i tried writing this code:

TextMagicServices.TextMagicMessageService TMS;
protected void Page_Load(object sender, EventArgs e)
{
string user = "username";
string pass = "password";

//initialize the Service
TMS = new TextMagicServices.TextMagicMessageService(user,
pass);

TextMagicServices.SentMessage objSentMessage = new
TextMagicServices.SentMessage();

string receivemsg = "";
receivemsg = receivemsg + TMS.receive(0);
Response.Write(receivemsg);

}

When i run this code, i get a blank page. Nothing comes out.

However when i try running the HTTP TRIGGER:
https://www.textmagic.com/app/api?username=myusername&password=mypassword&cmd=receive&last_retrieved_id=0

i receive this response on the browser:
{"messages":[{"message_id":2945184,"from":"61423871646","timestamp":
1316357140,"text":"James"},{"message_id":
2945867,"from":"61423871646","timestamp":1316409202,"text":"Hi"},
{"message_id":2945892,"from":"61423871646","timestamp":
1316411375,"text":"Sing a song"}],"unread":0}


Would you be able to tell me how to write the code to access the
receive message using the c# api? Thanks:)

Aleksey Ermakov

unread,
Sep 19, 2011, 7:27:34 AM9/19/11
to TextMagic SMS Gateway API
Hi,

I believe TMS.receive() method returns collection (List) of
ReceivedMessage objects not a string. So, need to iterate them first
in cycle. Not sure how to do it properly in C#, should be something
like this:

foreach (ReceivedMessage message in TMS.receive()) // Loop through
List with foreach
{
//use message object somehow
}


On Sep 19, 5:42 pm, levin <levin...@gmail.com> wrote:
> Hi there,
>
> Thanks so much for the prompt reply. However i don't really know how
> to write the full codes to make it work.
>
> Do i have to define any object to use the  TMS.receive(long
> lastRecievedId) method?
>
> With what you told me, i tried writing this code:
>
> TextMagicServices.TextMagicMessageService TMS;
>         protected void Page_Load(object sender, EventArgs e)
>         {
>             string user = "username";
>             string pass = "password";
>
>             //initialize the Service
>             TMS = new TextMagicServices.TextMagicMessageService(user,
> pass);
>
>            TextMagicServices.SentMessage objSentMessage = new
> TextMagicServices.SentMessage();
>
>             string receivemsg = "";
>             receivemsg = receivemsg + TMS.receive(0);
>             Response.Write(receivemsg);
>
>         }
>
> When i run this code, i get a blank page. Nothing comes out.
>
> However when i try running the HTTP TRIGGER:https://www.textmagic.com/app/api?username=myusername&password=mypass...
Reply all
Reply to author
Forward
0 new messages