ActiveXperts SMS Component

Quicklinks

Visual C#.NET sample - Send SMS text through an HTTP 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 a C# application project named 'DemoApp'. 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 on the command prompt.

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

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 Visual C# .NET Project

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

Visual C dotNET

(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:

Visual C dot NET

(Click on the picture to enlarge)

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

Step 4: Declare and create the ActiveXperts SMS Component objects

The following code will show you how to declare and create the HTTP and SMS objects. We will use the 'objHttp' object to send the message itself. The 'objSmsMessage' object will be used to store information of the message and the 'objSmsConstants' object containes constant values releated to the SMS objects.

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

class HttpProgram
{        
  static void Main(string[] args)
  {
    object obj;

    Http objHttp = new Http();
    SmsMessage objSmsMessage = new SmsMessage();
    SmsConstants objSmsConstants = new SmsConstants();

Step 5: Gather information

The following code will ask the user for the recipient telephone number and the content of the text message. This data will be stored in the 'objSmsMessage' object.

// Prompt user for an HTTP Post URL. By default, the ActiveXperts HTTP gateway is used
strUrl = GetHttpURL(objSmsConstants);

objSmsMessage.Clear();
objSmsMessage.ToAddress = "+31612345678"
objSmsMessage.BodyFormat = objSmsConstants.BODYFORMAT_TEXT;
objSmsMessage.Body = "Hello, world!"

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.

// Send the message !
obj = objSmsMessage;
objHttp.SendSms(ref obj, objSmsConstants.MULTIPART_OK);
Console.WriteLine("SendSms, result: " + objHttp.LastError );

Appendix: Full source code

Following you can find the full source code which is also included in the ActiveXperts SMS Component package.

//-----------------------------------------------------------------------
// <copyright file="HttpProgram.cs" company="ActiveXperts">
//     Copyright (c) ActiveXperts Software - www.activexperts.com
// </copyright>
// <author>ActiveXperts</author>
//-----------------------------------------------------------------------

namespace HttpProgram
{
  using System;
  using System.IO;
  using AxSms;
  using Microsoft.Win32;

  class HttpProgram
  {        
    static void Main(string[] args)
    {
      object obj;

      Http objHttp = new Http();
      SmsMessage objSmsMessage = new SmsMessage();
      SmsConstants objSmsConstants = new SmsConstants();

      string strUrl = string.Empty;

      // Set Logfile (optional, for debugging purposes)
      objHttp.LogFile = string.Format("{0}{1}", Path.GetTempPath(), "HttpPostLog.txt");

      Console.WriteLine("SMS Component: Build: " + objHttp.Build );
      Console.WriteLine(string.Empty);

      // Prompt user for an HTTP Post URL. By default, the ActiveXperts HTTP gateway is used
      strUrl = GetHttpURL(objSmsConstants);

      objSmsMessage.Clear();
      objSmsMessage.ToAddress = "+31612345678"
      objSmsMessage.BodyFormat = objSmsConstants.BODYFORMAT_TEXT;
      objSmsMessage.Body = "Hello, world!"

      objHttp.Url ="post.activexperts.com?username=myid&password=sa1&text=hello&to=0612345678;

      // Send the message !
      obj = objSmsMessage;
      objHttp.SendSms(ref obj, objSmsConstants.MULTIPART_OK);
      Console.WriteLine("SendSms, result: " + objHttp.LastError );
      Console.WriteLine("Response from provider: " + objHttp.LastResponseCode);
      Console.WriteLine("Ready.");
    }        
  }
}

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.