Here on the SMSified blog, we’ve provided lots of examples of how to use the SMSified API to quickly and easily send outbound text messages.

Using C# to send SMS messages

If you review some of our previous posts, you’ll see lots of good examples and tutorials on using PHP, Ruby and Node.js to send outbound SMS messages. With all of that in mind, I thought it was time to work up a quick example for our friends that use C#.

While we don’t yet have a C# library for working with our API (we’re working on one), it’s really easy to send outbound text messages with C# using SMSified.

The only potentially confusing issue with using C# with SMSified has to do with how the C# HttpWebRequest class uses authentication credentials.

When you use the Credentials property on the HttpWebRequest class, your application will expect to receive a challenge for credentials via an HTTP 401 response with an authentication realm. SMSified will not return an authentication realm with a 401 response, so trying to authenticate this way to send an outbound SMS message will fail.

The proper way to authenticate with SMSified is to send your credentials (via HTTP basic authentication) in a header on the original HTTP request. This is pretty straightforward in C#:

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
string authInfo = "username:password";
authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
req.Headers["Authorization"] = "Basic "   authInfo;

In the above example, “username” and “password” would be replaced with your SMSified credentials.

A full working example of sending an outbound text message in C# using SMSified can be found here.

We’ll be announcing the release of our C# library in the near future, but if you would like to incorporate SMS messages into your C# application, this post and sample code will get you started.

©2011 SMSified. All Rights Reserved.

.

©2011 Voxeo Labs. All Rights Reserved.

.

Originally from All Voxeo Blogs Feed