ActiveXperts SMS Messaging Server

Quicklinks

Create an SMS message using the SMS Messaging Server API - Visual C# .NET

SMS Messaging Server is an SMS messaging framework that enables companies to send, receive and process SMS- and e-mail messages. The framework is designed support virtually any scenario where low-and high volume SMS messaging is required. Use SMS Messaging Server in the following scenarios:

  • Mobile users query a database; results are sent back via SMS or e-mail;
  • Mobile users receive important information via SMS or e-mail while they are away from the office;
  • Stock prices are sent automatically via SMS and/or e-mail, daily;
  • Remote workers can update their worksheet from a remote location trough SMS;
  • ICT administrators restart/reboot servers and/or daemons from remote by SMS;
  • Setup an SMS voting system, supporting SMS and/or e-mail;
  • Etc.

SMS Messaging Server can be well integrated into VBScript environments. This document describes how the SMS Messaging Server can be integrated into your own projects.


Introduction

In this example we are going to create a Visual C#.NET sample page to create an SMS using the ActiveXperts SMS Messaging Server API. The SMS Messaging Server service will send the message you created in the database.

Step 1: Download and install SMS Messaging Server

Download ActiveXperts SMS Messaging Server 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: 'Console Application'. Select a name for the application and a name for the solution. Also, select the directory where you want to store the project:

Visual Csharp

(Click on the picture to enlarge)

Step 3: Refer to the SMS Messaging Server Library and create the objects

Now that a new project has been created, you must add a reference to the SMS Messaging Server API in the project to be able to use the it. 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 Messaging Server API Type Library as shown in the following picture:

Visual Csharp

(Click on the picture to enlarge)

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

On top of your code, type the following line to use the SMS Messaging Server API namespace:

namespace CreateSms

In your Main function, declare and create the following objects:

XMessageDB objMessageDB = new XMessageDB(); XConstants objConstants = new XConstants();

Step 4: Save the SMS Message

The following code shows how to send an SMS message:

objMessageDB.Save(ref ob); Console.WriteLine("Save, result: {0} ({1})", objMessageDB.LastError, objMessageDB.GetErrorDescription(objMessageDB.LastError)); if (objMessageDB.LastError == 0) PrintMessage(objMessage);

Appendix: Full source code

The following code shows how to send an SMS message using the SMS Messaging Server API:

using System; using System.Collections.Generic; using System.Text; using AXMMCFGLib; namespace CreateSms { class CreateSms { static void Main(string[] args) { XMessageDB objMessageDB = new XMessageDB(); XConstants objConstants = new XConstants(); string strRecipient, strBody; Console.WriteLine("API Module: {0}\nAPI Build: {1}\n", objMessageDB.Module, objMessageDB.Build); objMessageDB.Open(true); Console.WriteLine("Open, result: {0} ({1})", objMessageDB.LastError, objMessageDB.GetErrorDescription(objMessageDB.LastError)); if (objMessageDB.LastError != 0) return; Console.WriteLine("Enter recipient's mobile number (like: +4412345678): "); strRecipient = Console.ReadLine(); Console.WriteLine("Enter body of the message: "); strBody = Console.ReadLine(); object ob = (object)objMessageDB.Create(); Console.WriteLine("Create, result: {0} ({1})", objMessageDB.LastError, objMessageDB.GetErrorDescription(objMessageDB.LastError)); if (objMessageDB.LastError != 0) return; IXMessage objMessage = (IXMessage)ob; Console.WriteLine("RecordID: {0}", objMessage.ID); objMessage.DirectionID = objConstants.MESSAGEDIRECTION_OUT; objMessage.TypeID = objConstants.MESSAGETYPE_SMS; objMessage.StatusID = objConstants.MESSAGESTATUS_PENDING; objMessage.ChannelID = 0; objMessage.ScheduledTime = ""; objMessage.ToAddress = strRecipient; objMessage.Body = strBody; objMessageDB.Save(ref ob); Console.WriteLine("Save, result: {0} ({1})", objMessageDB.LastError, objMessageDB.GetErrorDescription(objMessageDB.LastError)); if (objMessageDB.LastError == 0) PrintMessage(objMessage); objMessageDB.Close(); Console.WriteLine("Closed."); Console.WriteLine("Ready."); } static void PrintMessage(IXMessage objMessage) { Console.WriteLine(" ID : {0}", objMessage.ID); Console.WriteLine(" Direction : {0}", objMessage.DirectionID); Console.WriteLine(" Type : {0}", objMessage.TypeID); Console.WriteLine(" Status : {0}", objMessage.StatusID); Console.WriteLine(" StatusDetails : {0}", objMessage.StatusDetailsID); Console.WriteLine(" ChannelID : {0}", objMessage.ChannelID); Console.WriteLine(" MessageReference : {0}", objMessage.MessageReference); Console.WriteLine(" ScheduledTime : {0}", objMessage.GetScheduledTimeString()); Console.WriteLine(" LastUpdate : {0}", objMessage.GetLastUpdateString()); Console.WriteLine(" Sender : {0}", objMessage.FromAddress); Console.WriteLine(" Recipient : {0}", objMessage.ToAddress); Console.WriteLine(" Subject : {0}", objMessage.Subject); Console.WriteLine(" BodyFormat : {0}", objMessage.BodyFormatID); Console.WriteLine(" Body : {0}", objMessage.Body); Console.WriteLine(" Trace : {0}", objMessage.Trace); } } }

You can download the full source code of this project from the ActiveXperts FTP site: ftp.activexperts-labs.com/samples/sms-messaging-server. 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 SMS Messaging Server 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.