You are here:
ActiveXperts.com > SMS Messaging Server > How to create a new Message > Visual C# .NET
Quicklinks
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:
SMS Messaging Server can be well integrated into VBScript environments. This document describes how the SMS Messaging Server can be integrated into VBScript projects.
Download ActiveXperts SMS Messaging Server from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.
Launch Microsoft Visual Studio (for instance 'Microsoft Visual Studio 2005') from the Start menu. Choose 'New' from the 'File' menu and click on 'Project'. In the 'New Project' dialog, select a Visual Studio template (for instance: 'Console Application'). Select a name for the application (for instance: 'DemoApp') and a name for the solution (for instance: 'DemoSolution'). Also, select the directory where you want to store the project (for instance: 'C:\MyProjects):
(Click on the picture to enlarge)
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:
(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:
using AXMMCFGLib;
In your Main function, declare and create the following objects:
private IXMessageDB objMessageDB; private IXConstants objConstants; objMessageDB = new XMessageDB(); objConstants = new XConstants();
You can now send an SMS message.
The following code shows how to send a SMS message:
using System;
using System.Collections.Generic;
using System.Text;
using AXMMCFGLib;
namespace CreateSmsMessage
{
class Program
{
private IXMessageDB objMessageDB;
private IXConstants objConstants;
public Program()
{
objMessageDB = new XMessageDB();
objConstants = new XConstants();
}
static void Main(string[] args)
{
Program prog = new Program();
prog.CreateSmsMessage();
}
public void CreateSmsMessage ()
{
objMessageDB.Open();
if (objMessageDB.LastError > 0)
{
Console.WriteLine("Failed to open message database, error: {0}", objMessageDB.LastError);
return;
}
object ob = (object) objMessageDB.Create();
IXMessage objMessage = (IXMessage)ob;
if (objMessageDB.LastError > 0)
{
Console.WriteLine("Create Failed, error: {0}", objMessageDB.LastError);
return;
}
Console.WriteLine("Message successfully created, recordID: {0}", objMessage.ID);
objMessage.Direction = objConstants.MESSAGEDIRECTION_OUT;
objMessage.Type = objConstants.MESSAGETYPE_SMS;
objMessage.Status = objConstants.MESSAGESTATUS_PENDING;
objMessage.ChannelID = 0;
objMessage.ScheduledTime = "";
objMessage.Recipient = "+31624896641";
objMessage.Body = "SMS Messaging Server - Test SMS Message";
objMessageDB.Save( ref ob );
if (objMessageDB.LastError > 0)
{
Console.WriteLine("Update message failed, error: {0}" , objMessageDB.LastError);
return;
}
PrintMessage ( objMessage.ID );
objMessageDB.Close();
}
void PrintMessage(int numID)
{
IXMessage objMessage = ( IXMessage ) objMessageDB.Load(numID);
if (objMessageDB.LastError > 0 )
{
Console.WriteLine("Failed to load message {0}", numID);
return;
}
Console.WriteLine(" ID : {0}", objMessage.ID);
Console.WriteLine(" Direction : {0}", objMessageDB.GetDirectionDescription(objMessage.Direction) );
Console.WriteLine(" Type : {0}", objMessageDB.GetTypeDescription(objMessage.Type) );
Console.WriteLine(" Status : {0}", objMessageDB.GetStatusDescription(objMessage.Status));
Console.WriteLine(" StatusDetails : {0}", objMessageDB.GetStatusDetailsDescription(objMessage.StatusDetails));
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.Sender);
Console.WriteLine(" Recipient : {0}", objMessage.Recipient);
Console.WriteLine(" Subject : {0}", objMessage.Subject);
Console.WriteLine(" Body : {0}", objMessage.Body);
Console.WriteLine(" Trace : {0}", objMessage.Trace);
}
}
}