Click here to Skip to main content
15,884,425 members
Articles / Programming Languages / C#
Article

Create WAP Push SMS Messages

Rate me:
Please Sign up or sign in to vote.
4.54/5 (29 votes)
25 Jul 20044 min read 502K   3.6K   91   115
How to generate a WAP Push SMS message for sending content to mobile phones.

Introduction

WAP Push SMS messages are widely used for pushing polyphonic ringtones and wallpaper images to mobile phones. However, as you will see, they also present a compelling method of directing people to WAP sites without visibility on the operator's WAP Portals.

This article presents a set of C# classes that generate an SMS message that instructs a mobile to browse to a given URL.

Instructing The Device

WAP Push messages can contain a number of different bodies all designed to accomplish slightly different outcomes. The one we are interested in is the Service Indication. This is an XML document (DTD here) that contains a URL for the handset to browse to. For example:

XML
<si>
  <indication href="http://wap.yahoo.com/" action="signal-high">
    A WAP Push to the Yahoo site
  </indication
</si>

In the mobile world, bandwidth and reliable connections are at a premium, so the method for getting this message to a device needs to be reliable and compact. XML has many strengths, compactness however is not one of them. Step in SMS and WBXML.

SMS is a reliable (depending on the service provider) store and forward mechanism for sending messages to mobile devices. Its use is not limited to person to person communication. It drives voice mail alerts, phone configurations, MMS notifications, and a whole host of other features we expect from mobile networks. The problem is that it is restricted to 140 bytes of data.

WBXML is binary format of XML that allows for compact transmission, while still preserving the structure and content of XML documents. Devices have inbuilt knowledge of certain XML DTDs that they are able to parse and understand.

One way this compactness is achieved is by a Tag Code Space being reserved for each DTD. Instead of the full tag name being sent, just a byte value is used to indicate the presence and position of the Tag. The Tag Code Space for the Service Indication DTD is shown below:

TagByte Value
si0x05
indication0x06

Another method is to replace common attributes and known values with byte values. In the case of the action attribute of the indication tag, which gives an indication of what level of interruption the device should attempt on receipt of this message, these are:

AttributeByte Value
action="signal-none"0x05
action="signal-low"0x06
action="signal-medium"0x07
action="signal-high"0x08
action="signal-delete"0x09

Use of these methods allow the XML document to be compressed sufficiently for transmission by SMS to the target device. A full description of the Service Indication can be found at the WAP Forum section of the Open Mobile Alliance web site.

Pushing The Instruction

Now that the instruction in the form of a Service Indication has been encoded, the data needs to be packaged into an SMS message. This requires two additional protocol layers to be wrapped around the instruction in order that it is read correctly by the recipient device.

The first layer is the WSP (Wireless Session Protocol). This is analogous to HTTP in the wired world, where a series of headers describe the content that is contained. As with the WBXML encoded Service Indication, these are actually transported as well known byte values in order to preserve bandwidth. The headers used in the WAP Push message are:

  • CONTENT-TYPE
  • CONTENT-LENGTH
  • APPLICATION-TYPE

Finally, the WDP (Wireless Datagram Protocol). For those of you who are familiar with sending Smart Messages to Nokia phones like VCard, Ringtones, Operator Logos, etc., this is the UDH (User Data Header). This contains an information element that describes the destination port on the mobile phone. This is used by the phone to decide which application it should fire up on receipt of this message. In our case, the WAP Browser.

Once all the layers are in place, you now have a series of bytes that have to be submitted to the mobile phone.

Using the code

The core classes comprise a ServiceIndication which is responsible for creating the content of the push; and PushMessage which is responsible for generating the complete message by wrapping the additional protocol layers. The classes WBXML, WSP, and WDP are holders for constants and statistics relating to the different protocol layers. The following code demonstrates how the body is generated:

C#
string href = "http://wap.yahoo.com";
string text = "A WAP Push to the Yahoo site";

PushMessage message = new PushMessage(href, text);
HexDecoder decoder = new HexDecoder();

string body = new string(decoder.GetChars(message.GetSMSBytes()));

I have included a HexDecoder class we use internally for converting a byte array into Hex string.

Once the message body has been created, it's a simple process to send the message using a mobile phone connected to the PC's serial port, or an SMS Web Service such as this.

Points of Interest

The great thing about sending these kinds of messages to mobile phones is that they ignore them if they don't understand them. It makes debugging a nightmare.

I started with the Service Indication specification on the OMA web site but discovered that the handsets out there are not as up-to-date. In order to get this to work, I had to drop the creation and expiry attributes as well as drop the version number to 1.1.

The ServiceIndication class encodes itself to WBXML in a fairly procedural way. Tempted as I was to write a generic WBXML encoder, XP teaches us that simple is good ;).

The content length byte value in the WSP header has the high byte set, which suggests that the content is restricted to 128 bytes. This makes sense given the 140 bytes available, if anyone can clarify the position on this, I would appreciate it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Chief Technology Officer Esendex
United Kingdom United Kingdom
Co-founder and CTO of Esendex the SMS service provider, whose life is better because of XP and .NET.

Comments and Discussions

 
GeneralMen Pin
Diwesh kumar4-Jan-12 4:46
Diwesh kumar4-Jan-12 4:46 
General00923242024500 Pin
nomi shani30-May-11 19:48
nomi shani30-May-11 19:48 
General03242024500 Pin
nomi shani30-May-11 19:41
nomi shani30-May-11 19:41 
GeneralSend wap push message with GSM modem Pin
noah lubko21-Mar-11 5:06
noah lubko21-Mar-11 5:06 
Generalsms voting Pin
wire2airindia26-Jun-10 6:42
wire2airindia26-Jun-10 6:42 
Newssms gateway , mobile marketing, sms Pin
wire2airindia10-Jun-10 2:56
wire2airindia10-Jun-10 2:56 
Questionmath.floor??!? Pin
DutchRhino23-Nov-09 3:09
DutchRhino23-Nov-09 3:09 
AnswerRe: math.floor??!? Pin
Adam Bird24-Nov-09 22:12
Adam Bird24-Nov-09 22:12 
GeneralRe: math.floor??!? Pin
DutchRhino24-Nov-09 22:24
DutchRhino24-Nov-09 22:24 
GeneralRing tones download from Asp.Net web site Pin
miltash27-Sep-09 22:08
miltash27-Sep-09 22:08 
GeneralRe: Ring tones download from Asp.Net web site Pin
Adam Bird28-Sep-09 22:21
Adam Bird28-Sep-09 22:21 
GeneralRe: Ring tones download from Asp.Net web site Pin
dcornel_200730-Oct-09 13:35
dcornel_200730-Oct-09 13:35 
QuestionMulti part message Pin
kiwiju1-Jul-09 0:32
kiwiju1-Jul-09 0:32 
AnswerRe: Multi part message Pin
Mtidings7-Jul-09 14:20
Mtidings7-Jul-09 14:20 
GeneralRe: Multi part message Pin
Adam Bird7-Jul-09 22:27
Adam Bird7-Jul-09 22:27 
Generalweb service used [modified] Pin
Justin Pravin12-May-09 0:51
Justin Pravin12-May-09 0:51 
GeneralRe: web service used Pin
Adam Bird26-Jun-09 0:05
Adam Bird26-Jun-09 0:05 
GeneralThanks Pin
satalaj24-Feb-09 19:16
satalaj24-Feb-09 19:16 
GeneralThe planet of mobile Pin
rony4u27-Jul-08 4:29
rony4u27-Jul-08 4:29 
GeneralWAP teletext Pin
zmrcic7-Aug-07 3:07
zmrcic7-Aug-07 3:07 
GeneralRe: WAP teletext Pin
Adam Bird8-Aug-07 23:40
Adam Bird8-Aug-07 23:40 
GeneralRe: WAP teletext Pin
Adam Page16-Oct-07 21:12
Adam Page16-Oct-07 21:12 
QuestionHREF and SID not set. Pin
murphy score27-Jun-07 6:43
murphy score27-Jun-07 6:43 
AnswerRe: HREF and SID not set. Pin
Adam Bird22-Jul-07 17:23
Adam Bird22-Jul-07 17:23 
In this project, I've only looked at using Service Indications in the context of deliverying WAP links to mobile phone browsers as that's all we needed.

It should be relatively simple to extend the code to support the full schema.



GeneralVery Nice Article!!!!!!! Pin
osamahmirza11-Jun-07 18:28
osamahmirza11-Jun-07 18:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.