Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

SMS Messaging Using the .NET Compact Framework

SMS messaging may have it's drawbacks, but it's benefits make it a viable solution for many of today's enteprise applications. This article uses a sample hospital application to show you how to integrate SMS messaging using the .NET Compact Framework.


advertisement
MS messaging is one of the many ways in which your Windows Mobile application[s] connect to the outside world. The key advantage to SMS is that as long as the device has a valid SIM card, it is able to send and receive SMS messages. Unlike using web services (which uses a request and response communication model), SMS messaging is asynchronous in nature—messages are sent and received as and when needed. Also unlike sockets programming, SMS messaging does not require building a client and server in order to send and receive data—all relaying is taken care of by the cellular network. There are downsides, however: Using SMS messaging can be costly and delivery is non-guaranteed. That said, SMS messaging is still a viable solution for many enterprise applications in use today.

This article will show you how to use SMS messaging in a real-world application. The sample application is used in a hospital where nurses are equipped with Windows Mobile devices. When a patient is admitted to the hospital, SMS messages are sent to the nurses in charge to notify them of the various events happening, such as patients' admission, patients' discharging, etc. The sample project uses the .NET Compact Framework to integrate SMS messaging into the application.

Sending SMS Message
Using Visual Studio 2008, create a new Windows Mobile 6 Professional application using C#. Name the project SMSMessaging.



To use SMS messaging in a Windows Mobile application, you need to add a reference to the following DLLs:

  • Microsoft.WindowsMobile.dll
  • Microsoft.WindowsMobile.PocketOutlook.dll
Populate the default Form1 with the controls shown in Figure 1.

Figure 1. Form1: Populating the default Form1 with the various controls.

For simplicity's sake, hardcode the lblEmployeeID control with a fixed employee ID. Also, add a few items into the cbbLocation control: Ward 1, Ward 2, Ward 3, and so on.

Switch to the code-behind of Form1 and import the following namespace:

using Microsoft.WindowsMobile.PocketOutlook;

Within the Form1 class, define the constant representing the phone number of the HQ where you can send acknowledgement messages to:

public partial class Form1 : Form { const string HQPhoneNo = "651234567";

In the first part of this project, you'll be enabling a nurse to send his/her location to a central server through SMS. Code the Send Location via SMS button as follows:

private void btnSendSMS_Click(object sender, EventArgs e) { try { SmsMessage sms = new SmsMessage() { Body = lblEmployeeID.Text + "|" + cbbLocation.Text }; sms.To.Add(new Recipient(HQPhoneNo)); sms.Send(); MessageBox.Show("Message sent!"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }

The SmsMessage class (located in the Microsoft.WindowsMobile.PocketOutlook namespace) allows you to send a SMS message to one or more recipients. In the code above, if a nurse is current in Ward 5, the application will send a SMS message with the following content (in the format <EmployeeID>|<Ward No.>):

745402|Ward 5



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap