Click here to Skip to main content
14,173,097 members
Click here to Skip to main content
Add your own
alternative version


91 bookmarked
Posted 9 Jun 2004

Create WAP Push SMS Messages

, 25 Jul 2004
Rate this:
Please Sign up or sign in to vote.
How to generate a WAP Push SMS message for sending content to mobile phones.


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:

  <indication href="" action="signal-high">
    A WAP Push to the Yahoo site


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

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

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:


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:

string href = "";
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.


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


About the Author

Adam Bird
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.

You may also be interested in...


Comments and Discussions

GeneralMen Pin
Diwesh kumar4-Jan-12 4:46
memberDiwesh kumar4-Jan-12 4:46 
General00923242024500 Pin
nomi shani30-May-11 19:48
membernomi shani30-May-11 19:48 
General03242024500 Pin
nomi shani30-May-11 19:41
membernomi shani30-May-11 19:41 
GeneralSend wap push message with GSM modem Pin
noah lubko21-Mar-11 5:06
membernoah lubko21-Mar-11 5:06 
Generalsms voting Pin
wire2airindia26-Jun-10 6:42
memberwire2airindia26-Jun-10 6:42 
Newssms gateway , mobile marketing, sms Pin
wire2airindia10-Jun-10 2:56
memberwire2airindia10-Jun-10 2:56 
Questionmath.floor??!? Pin
DutchRhino23-Nov-09 3:09
memberDutchRhino23-Nov-09 3:09 
AnswerRe: math.floor??!? Pin
Adam Bird24-Nov-09 22:12
memberAdam Bird24-Nov-09 22:12 
GeneralRe: math.floor??!? Pin
DutchRhino24-Nov-09 22:24
memberDutchRhino24-Nov-09 22:24 
GeneralRing tones download from Asp.Net web site Pin
miltash27-Sep-09 22:08
membermiltash27-Sep-09 22:08 
GeneralRe: Ring tones download from Asp.Net web site Pin
Adam Bird28-Sep-09 22:21
memberAdam Bird28-Sep-09 22:21 
GeneralRe: Ring tones download from Asp.Net web site Pin
dcornel_200730-Oct-09 13:35
memberdcornel_200730-Oct-09 13:35 
QuestionMulti part message Pin
kiwiju1-Jul-09 0:32
memberkiwiju1-Jul-09 0:32 
AnswerRe: Multi part message Pin
Mtidings7-Jul-09 14:20
memberMtidings7-Jul-09 14:20 
GeneralRe: Multi part message Pin
Adam Bird7-Jul-09 22:27
memberAdam Bird7-Jul-09 22:27 
Generalweb service used [modified] Pin
Justin Pravin12-May-09 0:51
memberJustin Pravin12-May-09 0:51 
GeneralRe: web service used Pin
Adam Bird26-Jun-09 0:05
memberAdam Bird26-Jun-09 0:05 
GeneralThanks Pin
satalaj24-Feb-09 19:16
membersatalaj24-Feb-09 19:16 
GeneralThe planet of mobile Pin
rony4u27-Jul-08 4:29
memberrony4u27-Jul-08 4:29 
GeneralWAP teletext Pin
zmrcic7-Aug-07 3:07
memberzmrcic7-Aug-07 3:07 
GeneralRe: WAP teletext Pin
Adam Bird8-Aug-07 23:40
memberAdam Bird8-Aug-07 23:40 
GeneralRe: WAP teletext Pin
Adam Page16-Oct-07 21:12
memberAdam Page16-Oct-07 21:12 
QuestionHREF and SID not set. Pin
murphy score27-Jun-07 6:43
membermurphy score27-Jun-07 6:43 
AnswerRe: HREF and SID not set. Pin
Adam Bird22-Jul-07 17:23
memberAdam Bird22-Jul-07 17:23 
GeneralVery Nice Article!!!!!!! Pin
osamahmirza11-Jun-07 18:28
memberosamahmirza11-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.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01 | 2.8.190524.3 | Last Updated 26 Jul 2004
Article Copyright 2004 by Adam Bird
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid