Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

SMS services in ASP.NET Mobile Web Application


Author: Balamurali Balaji MVP

SUMMARY

This article discusses the complete know-how of SMS services and the tools used for developing web based mobile applications in ASP.NET. It also deals with the components required for SMS services available in .NET compact framework.

↑ Back to the top


Reason for Annotation

This article is aimed at clarifying more information on using SMS services in mobile.net applications. Developers would find it useful in understanding the basic concepts behind using this service in their applications

↑ Back to the top


Abstract for Annotation

This article discusses about the SMS and its capabilities in detail. Also, it deals with variety of ways of using SMS enabled .net applications.

↑ Back to the top


Introduction

SMS – Short Messaging Service is quite a buzz word in the developing community nowadays. When it comes to .NET environment, developers are really into it finding a solution for sending and receiving SMS from their web applications. Most of the web applications have a SMS feature in-built enabling the users to send a simple text to mobile numbers for instant correspondence. For its speed, accuracy and increased productivity, SMS is one of the most successful services among the various wireless services.

↑ Back to the top


SMS capabilities

 
SMS is capable of delivering numerous data services to wireless devices, including voice-mail alerts, fax services, ring tones, games etc. A SMS may also be a TMS (Text-Messaging service). A wireless text message is a short string of up to 256 characters that can be sent to a mobile device.
 
Though the text messaging service was initially used with PAGER devices that support alpha-numeric numbers, it has found a place in the mobile phones also.
 
Many mobile wireless carriers have made it extremely difficult for developers to get into knowledge source of SMS and its features. They use different modes of handling SMS messages for many reasons. One of the reason is that the cost involved for the very message itself. Some carriers develop API for SMS that can send or receive SMS using the TCP/IP. Some others use protocols like Simple Network Paging Protocol (SNPP), the Wireless Communication Transport Protocol (WCTP), and the Short Message Peer to Peer (SMPP). Some carriers now expose a Simple Mail Transport Protocol (SMTP), an e-mail interface to send short text messages. In this case, the e-mail address will be the device's phone number or pager identification number, along with the wireless carrier's special domain. For example, a phone with Reliance service will have an e-mail address of 3135551212@mobile.Reliance.net.

↑ Back to the top


Requirements for SMS integration with any application

The prerequisite for using the SMS capabilities is the SMS gateway.  You can have access to the SMS with mobile network(service providers), via a web interface or an API. They would supply you with a set of APIs that work with their SMS servers.  Again, this involves a cost for sending messages and providing services.
 
Alternatively, there are a few mobile phone web sites that allow you to send/receive an SMS using their web site.  You can develop a web page in ASP.NET that can be posted to that site for providing SMS services to your users. In India, , , 
, are few websites that offer the SMS and related services for corporate and high volume SMSC links using SMPP (Short Message Peer to Peer) communication protocol.
 
A SMSC (Short Message Service Center) regulates the message transfer to and from the mobile phones in GSM-networks. This includes not only short text messages but also fax, voice- or e-mails. It delivers the messages, temporarily stores them in case the respective recipient is currently not available and takes care of charging. There is at least one SMSC per network.
 
The third option is considering a subscription to a SMS webservice using which you can send or receive SMS in your application. Go to

↑ Back to the top


GPRS

SMS services can be provided with the use of GPRS (General Packet Radio Service) that offers Internet email services. This would be the simplest form of providing SMS services in your applications.
 
GPRS facilitates continuous wireless connection to data networks and access to your favorite information and entertainment services. It allows mobile phones to be used for sending and receiving data over an Internet Protocol (IP)-based network. Besides SMS, other service protocols like WAP, MMS, SMS, Java and the PC dial-up (for example, Internet and e-mail) are also supported by GPRS.
 
Unlike SMS gateway services, Internet email services stores the messages using mailbox services. The emails are actually stored and the user gets a notification on their mobile phone and can then retrieve the full email by dialing in to collect it, forward it, and so on. Gateway services offers a wireless email platform wherein it simply translates the message from SMTP(the Internet email protocol) into SMS and sends to the SMS Center.
 
Most of the times, on receiving a new email, Internet email users do not get notifications on their mobile phones. They need to dial in periodically to check their mailbox. However, we can link the Internet email system with an alert mechanism such as SMS or GPRS, and users can be notified when a new email is received.

↑ Back to the top


SMS services in .NET applications

The Mobile Internet Toolkit (MMIT) from Microsoft also called as ASP.NET mobile controls is an extension to the .NET Framework and ASP.NET that allows developers to write mobile Web applications targeting multiple devices such as cell phones and PDAs. The MMIT frees the developer to concentrate on the application logic and leave the UI rendering to the runtime. To install MMIT, you need to have the Microsoft .NET Framework version 1.0 or later. Because MMIT is an extension of ASP.NET you must also have IIS running.
 
Mobile applications are of two types: Web-based and device based.
 
Web based mobile applications run on the server, typically the Web server, and is accessed by mobile devices through the Internet and SMS services provided by Internet Email messages.
 
Device specific mobile applications are standalone applications running on the devices itself, with or without Internet access. For this type of application, Microsoft provides a scaled-down version of the .NET Framework—the .NET Compact Framework (.NET CF).

↑ Back to the top


SMS services in .NET CF applications

 
 
.NET Compact Framework applications target devices like Pocket PCs, Smart Phones, PDAs. It is based on Windows CE. The core set of functions for smart-device systems and applications are available in COREDLL.DLL. It also has the following dlls:
 
AYGShell.dll – Pocket PC shell functions
CommCtrl.dll – Common control lib
WinSock.dll – Windows Sockets
Phone.dll – High level phone control
SMS.dll – SMS messaging API
 
Using the P/Invoke support available in .NET CF for calling Win32 API functions in unmanaged dlls, we can send SMS from a C# or VB.NET CF application.
 
SmsOpen function opens the SMS messaging component.
 
HRESULT SmsOpen (
const LPCTSTR ptsMessageProtocol,
const DWORD dwMessageModes,
SMS_HANDLE* const psmshHandle,
HANDLE* const phMessageAvailableEvent);
 
ptsMessageProtocol is a string denoting that SMS protocol to use. dwMessageModes specifies whether we want to be in send or receive mode.
psmshHandle is a pointer to the handle of the SMS session and is valid only if the function returns properly. phMessageAvailableEvent is the handle to a Win32 event handle that can be used to determine when the next message is available to be read.
 
Using the DllImport attribute in the System.Runtime.InteropServices namespace, we can declare the functions in our code.
 

 
[DllImport("sms.dll")]
   private static extern IntPtr SmsOpen(String ptsMessageProtocol,
     IntPtr dwMessageModes, ref IntPtr psmshHandle, IntPtr
     phMessageAvailableEvent);
 

 
SmsSendMessage function sends the message to a mobile number.
 
HRESULT SmsSendMessage (
const SMS_HANDLE smshHandle,
const SMS_ADDRESS * const psmsaSMSCAddress,
const SMS_ADDRESS * const psmsaDestinationAddress,
const SYSTEMTIME * const pstValidityPeriod,
const BYTE * const pbData,
const DWORD dwDataSize,
const BYTE * const pbProviderSpecificData,
const DWORD dwProviderSpecificDataSize,
const SMS_DATA_ENCODING smsdeDataEncoding,
const DWORD dwOptions,
SMS_MESSAGE_ID * psmsmidMessageID);
 
smshHandle is the handle returned in psmshHandle by SmsOpen. psmsaSMSCAddress is an optional parameter specifying which SMS Message Center is to be used. If NULL is used, the user's default SMSMC will be used.
psmsaDestinationAddress is where the message is to be delivered. pstValidityPeriod breaks from the standard SYSTEMTIME structure in that it is the amount of time past sending of an SMS during which the message still is considered valid.
pbData is the byte representation of the message's data portion. This can be NULL.
dwDataSize is the size in bytes of the message's data portion. pbProviderSpecificData is additional information required by some providers to allow an SMS to transmit correctly. dwProviderSpecificDataSize is the size in bytes of the previously mentioned field.
smsdeDataEncoding is an option found within the SMS_DATA_ENCODING enumeration detailed above. dwOptions are (currently) two flags that will fail an SMS after one attempt or will allow it to be redelivered until the router gives up. psmsmidMessageID will be non-null if this function returns successfully.
 
In our managed code, we use it as
 

 
[DllImport("sms.dll")]
private static extern IntPtr SmsSendMessage(IntPtr smshHandle, IntPtr
  psmsaSMSCAddress, IntPtr psmsaDestinationAddress, IntPtr
  pstValidityPeriod, byte[] pbData, IntPtr dwDataSize, byte[]
  pbProviderSpecificData, IntPtr dwProviderSpecificDataSize,
  SMS_DATA_ENCODING smsdeDataEncoding, IntPtr dwOptions,  IntPtr
  psmsmidMessageID);
 

 
SmsClose function closes an SMS message service request.
 
HRESULT SmsClose (
const SMS_HANDLE oCommandBarPopup);
 

 
In our code we declare it as
 
[DllImport("sms.dll")]
   private static extern IntPtr SmsClose(IntPtr smshHandle);
 

 

↑ Back to the top


SMS services in ASP.NET Mobile Web Applications

In this sample, I use an already existing webservice from www.webservicex.com. It provides Web Service Definition Language (WSDL) link for sending SMS. You must add a web reference to the following webservice in your CF.NET application:
 
http://www.webservicex.net/SendSMS.asmx
 

 
Private void SendMessage(string MobileNumber, string  FromEmailAddress, string  Message)
{
localhost.SendSMS smsService = New localhost.SendSMS();
 
try
{
            bool result = smsService.SendMessage(someMobileNumber,
myemaidid, myMessage);
 
            if (result == True)
                MessageBox.Show("The message was sent", "SMS Messaging");
            else
                MessageBox.Show("The message was not sent", "SMS Messaging");
    catch (SoapException ex)
        MessageBox.Show("An exception occured.  " & ex.Detail.InnerText, "SMS Messaging");
}
 
}

 

↑ Back to the top


Conclusion

Developing applications that provide SMS services is not a simple task. You must install the appropriate tools and components in your system to develop mobile applications in .NET environment.
 
If you are developing a mobile based SMS service, you need to rely on SMS gateway software components or you can make use of existing webservice which uses them. There is another finest way of providing SMS capability to your application that uses the AT commands which comes as a variety of sets for different mobile devices. This is not discussed in this article.
 
If you are developing a device based SMS service application, you can go for .NET compact framework that is being shipped with Visual Studio .NET 2003/2005  or you can download it from the internet. Here again, most of the dll components you need for developing SMS services are available with Windows CE  4.2/5.0 SDK toolkit, not available with  .NET CF.
 
Hope you enjoyed reading this article. If you have any comments or suggestions, please feel free to contact me at .

↑ Back to the top


Community solutions content disclaimer

Microsoft corporation and/or its respective suppliers make no representations about the suitability, reliability, or accuracy of the information and related graphics contained herein. All such information and related graphics are provided "as is" without warranty of any kind. Microsoft and/or its respective suppliers hereby disclaim all warranties and conditions with regard to this information and related graphics, including all implied warranties and conditions of merchantability, fitness for a particular purpose, workmanlike effort, title and non-infringement. You specifically agree that in no event shall Microsoft and/or its suppliers be liable for any direct, indirect, punitive, incidental, special, consequential damages or any damages whatsoever including, without limitation, damages for loss of use, data or profits, arising out of or in any way connected with the use of or inability to use the information and related graphics contained herein, whether based on contract, tort, negligence, strict liability or otherwise, even if Microsoft or any of its suppliers has been advised of the possibility of damages.

↑ Back to the top


Keywords: kb, kbpubmvp, kbpubtypecca, kbpubtypedc, kbhowto, KB555578

↑ Back to the top

Article Info
Article ID : 555578
Revision : 6
Created on : 8/15/2018
Published on : 8/15/2018
Exists online : False
Views : 117