ActiveXperts SMS Component

Quicklinks

ASP.NET (C#) sample - Send SMS text through an SMPP provider

The ActiveXperts SMS Component is a software development kit (SDK) to enhance an application or script with SMS or Pager functionality. SMS messages can be sent/received using a GSM modem, an SMPP provider or an HTTP compliant SMSC.


Introduction

In this example we are going to use Visual Studio 2008 to create an ASP.NET C# project named 'DemoApp' in a solution named 'DemoSolution'. We are going tot store this project in the directory 'C:\MyProjects'. All of these names can be changed according to your preferences. This demo project will ask the user to give a phone number and a message body in the web interface.

A subscription to an SMPP provider is required. For this demo you can send a limited number of messages through our own gateway.

Prerequisites

You must install and configure Internet Information Services (IIS) before using the ActiveXperts SMS Component with ASP .NET

If you don't have IIS installed, use the following steps:

  • From the Control Panel, click 'Add/Remove Programs'. Select the 'Add/Remove Windows Components' icon from the left pane, then select 'Application Server' and click on 'Details'. You can now select both 'ASP .NET' and 'Internet Information Services (IIS)'. Click 'OK' to continue installation;

Step 1: Download and install the ActiveXperts SMS Component

Download the the ActiveXperts SMS Component from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.

Step 2: Create a new ASP .NET C# Project

Launch Microsoft Visual Studio from the Start menu. Choose 'New' from the 'File' menu and click on 'Web Site'. In the 'Web Site' dialog, select ASP .NET Web Site. Select a name for the application and a name for the solution. Also, select the directory where you want to store the project:

ASP.NET Visual Csharp.NET

(Click on the picture to enlarge)

Step 3: Refer to the ActiveXperts SMS Component Library

Now that a new project has been created, you must add a reference to the ActiveXperts SMS Component in the project to be able to use the the ActiveXperts SMS Component objects. To do so, choose 'Add Reference...' from the 'Project' menu. In the 'Add Reference' dialog that pops up, select the 'COM' tab and select the ActiveXperts SMS Component Type Library' as shown in the following picture:

ASP.NET Visual C#.NET

(Click on the picture to enlarge)

Click 'OK' to close the 'Add Reference' dialog.

Step 4: Declare and create the SMPP objects

On top of your code, type the following line to use the ActiveXperts SMS Component namespace:

using System;
using System.IO;
using System.Threading;
using AxSms;
using Microsoft.Win32;

class SmppProgram
{
  static void Main(string[] args)
  {
    Smpp objSmpp = new Smpp();
    SmsMessage objSmsMessage = new SmsMessage();
    SmsConstants objSmsConstants = new SmsConstants();

Gather information

The following code will get the information you entered in the text fields, and store this information in the 'objSmsMessage' object. If the multipart checkbox is selected, then the SMS message will be sent as a multipart message (multiple SMS's).

objSmsMessage.Clear();
objSmsMessage.RequestDeliveryReport = true;
objSmsMessage.ToAddress = txtToAddress.Text;
objSmsMessage.Body = txtMessage.Text;
objSmsMessage.BodyFormat = objSmsConstants.BODYFORMAT_TEXT;

if (cbxFlash.Checked)
{
  objSmsMessage.DataCoding |= objSmsConstants.DATACODING_FLASH;
}

int iMultipart;

if (cbxMultipart.Checked)
{
  iMultipart = objSmsConstants.MULTIPART_OK;
}
else
{
  iMultipart = objSmsConstants.MULTIPART_TRUNCATE;
}

Step 6: Send SMS messages

The following code shows how to send an SMS message using the data that was stored in the 'objSmsMessage' and 'objSmsConstants' objects. After the message is sent the error result will be displayed. Error 0 means the message was sent succesfully.

obj = objSmsMessage;
objSmpp.SubmitSms(ref obj, iMultipart);

if (objSmpp.LastError != 0)
{
  UpdateResult(objSmpp.LastError);
  return;
}

You can download the full source code of this project from the ActiveXperts FTP site: ftp.activexperts-labs.com/samples/sms-component. There are many other working samples included with the product or on the FTP site.

NOTE: Demo Projects are created with Microsoft Visual Studio 2008

The ActiveXperts SMS Component project ships with a set of Microsoft Visual Studio .NET samples. The projects are created with Microsoft Visual Studio 2008.

Users with a later version of Microsoft Visual Studio can open such a project. The Visual Studio Conversion Wizard will guide you through the process of converting the project to the version used.