|
C#.NET SMS API
Download C#-SMS-API.zip
This page gives you information on how you can use .NET remoting
in C# to send/receive SMS messages. .NET remoting can be used to connect
to the Ozeki NG - SMS Gateway and makes it possible to send/receive SMS
messages using a GSM Modem or an IP SMS connections, such as SMPP,
CIMD2 or UCP/EMI. In my previous article
(How to send SMS messages
from C# using an SQL database) I have explained how you can send/receive
SMS messages from C# using databases. The information I present
here is useful if you would like to Interface directly with the SMS gateway
from C#.NET.
Introduction to the C# SMS API
The C# SMS API you may download from
this webpage
can be used to connect to Ozeki NG - SMS Gateway directly to send and receive
SMS messages from any C#.NET application. The API can be used to connect locally
or remotely (over a LAN or the Internet) to the
SMS Gateway. The API provides a classic example on how to use the .NET remoting
to make two applications (Your application and the SMS Gateway) work together.
It uses the advanteges provided by Client Activated Object (CAO) and
Server Activated Objects (SAO) technologies combined to create a client-server
model. The API comes with an example. The C# SMS example is a working example
(Figure 1) with full source code.
Figure 1. - Example application
A few words about .NET remoting
.NET remoting is an excellent tool for developing distributed applications.
It can be applied cross AppDomain boundaries, cross process boundaries on
local machine, cross machine boundaries on a LAN, cross machine boundaries
on a WAN (still in same environment). It is an ideal solution to connect
your C# application to the SMS gateway because it offers two way communication
between your application and the SMS gateway over a tcp socket channel.
Using .NET remoting we have a facility to send SMS messages
to the gateway and to receive event notifications about message transmissions,
message deliveries and incomfing SMS messages asynchrounously.
How to use the C# SMS API
To use the C# SMS API you have to perform the following steps:
- You should add the ozSMSAPI project to your solution and create
a reference to it in your main project
- In you code you should include the .NET remoting headers:
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels.Http;
using System.Runtime.Remoting.Lifetime;
|
- The next step is to register the remote class. This is discussed in
more detail in the "How to register remote objects in .NET remoting" guide.
- Next you need to create an instance of the class:
string url = "http://localhost:9502/ozSMSAPI";
SMSClientFactory factory = (SMSClientFactory)Activator.GetObject(typeof(SMSClientFactory), url);
mySMSClient = factory.CreateSMSClient();
|
- After you have created an instance of this class you can log
into the SMS gateway and you can send your first SMS:
if (mySMSClient.login("admin", "abc123"))
{
mySMSClient.sendMessage("+44204567897", "Hello world");
}
|
The C# SMS API reference
The C# SMS API provides methods that allow you to send various message types,
such as WAP Push, Flash SMS, Ringtones, VCard, VCalendar, etc. It also
has events that help you track your SMS messages. For example you can subscribe
for a notification about when a message was delivered to the network and
when a message was delivered to the handset. The C# SMS API can also be
used to receive SMS messages. This gives you the option to create applications
like SMS voting, quiz games, or stock market data querying quickly. A complete
documentation of the C# SMS API is available on the following webpage:
C# SMS API Reference
Alternatively you might find the following guide useful:
How to send and receive SMS messages from C# using an SQL compatible database
|