Facebook Like Box

Main Menu

Encoding SMS in PDU format in .NET

Many of applications ranging from Enterprise level to very small level Marketing solutions relay on SMS Services. If you are dealing with huge SMS rate than you might need and IP connectivity to the SMS Gateways and there are many Solutions available for that, but they are quite costly. If you are dealing with relatively lower numbers of SMS, Approximately (7000 - 10000 SMS per day) then you can choose

some cost effective solution and it is GSM Modem or Mobile devices. Certainly you need a software to drive GSM Modems, like Ozeki NG SMS Gateway.

But if you want to write your own SMS software you will need some library to encode and decode SMS in PDU format. Most of the devices understand the PDU format.

In this article I will demonstrate the SMS encoding to PDU format using an Open Source PDU Library written in C#. First of all checkout the latest version of SMS-PDU lib from google code hosting.

http://code.google.com/p/sms-pdu/

The library is quite simple to use. Lets create a test program to check the SMS encoding functionality.

  • Open Visual Studios 2010 and create a new C# console/Windows Form project.
  • Build the sms-pdu lib project.
  • Add reference to newly created DLL to your project, and this will include all SMS encoding and decoding classes to your project.

First, Lets see how to compose a single SMS. Following code will explain composing of single SMS.

 

//Compose PDU SMS
SMS sms = new SMS();
//Setting direction of sms
sms.Direction = SMSDirection.Submited;
//Sets the flash property of SMS
sms.Flash = false;
//Set the recipient number
sms.PhoneNumber = 0012713313311;
//Sets the Message encoding for this SMS
sms.MessageEncoding = SMS.SMSEncoding._7bit;
//sms.MessageEncoding = SMS.SMSEncoding.UCS2;
//Set the SMS Message
sms.Message = "This is a simple text message less than 160 characters.";
string messagesParts;
//Compose single sms
messagesParts = sms.Compose();
//messageParts is the composed PDU for single part sms encoded in 7 bit.

Now I will explain how to compose a multipart SMS using this library. it's pretty much simple as a single SMS with minor changes. See the following code.

//Compose PDU SMS
SMS sms = new SMS();
//Setting direction of sms
sms.Direction = SMSDirection.Submited;
//Sets the flash property of SMS
sms.Flash = false;
//Set the recipient number
sms.PhoneNumber = 0012713313311;
//Sets the Message encoding for this SMS
sms.MessageEncoding = SMS.SMSEncoding._7bit;
//sms.MessageEncoding = SMS.SMSEncoding.UCS2;
//Set the SMS Message
sms.Message = "This is a long text message greater than 160 characters. You can encode it to PDU format using the SMS-PDU lib for .NET, It also supports UCS-2 encoding, and special characters like { [ ] } are also supported. Its quite simple to use in your code.";
//now check for multipart sms
string[] messagesParts;
if (sms.Message.Length > 160)
{
    messagesParts = sms.ComposeLongSMS();
}
//messageParts is the composed PDU for multipart sms encoded in 7 bit.

Finally, If you want to compose Unicode SMS, it's also supported, All of the above coding remain same except


sms.MessageEncoding = SMS.SMSEncoding.UCS2; //setting encoding to Unicode.

I hope this library is easy to use, and will help you to build your own state of art SMS supported application.

Comments   

 
0 #7 Hard Code 2013-10-24 07:27
Quoting Ryan:
From memory I had to make some modifications to fix the ComposeLongSMS. It didn't work back in June without it, and the latest version hasn't been updated since. The fix is here: https://code.google.com/p/sms-pdu/issues/detail?id=4


Thanks, I will have a look on this issue, and will update the code accordingly on SVN.
Quote
 
 
0 #6 Hard Code 2013-10-24 07:06
ummarbhutta(at) gmail_dot_com
Quote
 
 
0 #5 Ryan 2013-10-24 07:06
From memory I had to make some modifications to fix the ComposeLongSMS. It didn't work back in June without it, and the latest version hasn't been updated since. The fix is here: https://code.google.com/p/sms-pdu/issues/detail?id=4
Quote
 
 
0 #4 Hard Code 2013-10-24 07:02
Quoting Stefan:
Please sent me that libraray..i hava oldest version without ComposeLongSms method ?

@Stefan, you can download the latest version from the SVN (google code repository) as given in post. If there is any issue please let me know.
Quote
 
 
0 #3 Ryan 2013-10-24 07:02
Quoting Stefan:
Please sent me that libraray..i hava oldest version without ComposeLongSms method ?


Post your email.
Quote
 
 
0 #2 Stefan 2013-08-28 12:28
Please sent me that libraray..i hava oldest version without ComposeLongSms method ?
Quote
 
 
0 #1 Ryan 2013-06-06 09:16
Exactly what I needed!
If only I found it 4 hours ago.

Thanks!
Quote
 

Add comment


Security code
Refresh