OZEKI
Message Server 6
"The world's favourite SMS server"
info@ozeki.hu
Tel.: 00 36 52 532 731

SMS Server 6
On-line manual
Introduction
SMS technology
MMS technology
About
Product features
Installation guide
User guide
Developers guide
General information
Languages
C++ SMS
SQL SMS
HTTP SMS
Files SMS
Java SMS
PHP SMS
ASP SMS
Delphi SMS
C# SMS
Access SMS
SMS FAQ
Case studies
Appendix
Search
Download
Home
Support
How to buy
Resellers
SMS Wall
IP SMS Gateway
Excel SMS
Company


On-line manual:
  Explore all the features in this on-line HTML documentation.
Product guide:
  This downloadable pdf explains all the features of Message Server 6.


Newsletter:
  Sign up to get news about product updates!

E-mail:
  You can send tech. questions in e-mail to the following address: info @ ozeki.hu


Did you know?
Ozeki offers a very high performance SMS Gateway system as well called Ozeki NG SMS Gateway. It can send and receive up to 500 SMS messages per second.

Ozeki Phone System XE VoIP PBX software is an advanced PBX built for automated voice calls and 2 way SMS messaging. It has outstanding APIs for software developers.

Ozeki VoIP SIP SDK is a great tool for software developers who wish to get involved in voip phone client or voip phone service development.

OZEKI MESSAGE SERVER - Product Guide

Delphi SMS Contents | SearchAccess SMS

Home > Developers guide > Languages > C# SMS

C# SMS

On this page C# developers can learn how to use the HTTP protocol for SMS messaging with the Ozeki Message Server.

Introduction

HTTP is the primary transport mechanism for communicating with resources over the World Wide Web. Developers often use this protocol because of its simplicity and popularity, and also because it enables them to bypass firewalls and proxies. HTTP is a request/response protocol between clients and servers. Using the Ozeki Message Server you can easily send SMS messages with a simple HTTP request. You can also receive SMS messages using the Ozeki SMS Server by implementing a very simple web server.

Configuration

If you would only like to send messages using the HTTP protocol, you do not need to configure the Ozeki Message Server. Therefore, you may as well skip this paragraph. However, if you also want to receive SMS Messages, you need to configure the OZEKI Message Server to enable it to act as an HTTP Client. For this, you need to install and configure a HTTP Client plugin. To find out how to install and configure the HTTP Client plugin, check out the following page:

HTTP Client Plugin. In the appropriate tab, you need to set a base URL where the messages will be sent.
(Example: http://127.0.0.1:9400/getresponse.php?sender=$SENDER&
                 receiver=$RECEIVER&msg=$MSG)

By configuring the HTTP Client plugin, you instruct the Ozeki Message Server to forward all incoming SMS messages to the base URL with the specified parameters. As a result, a web server listening on the base URL can easily process the messages.

Sending SMS using HTTP request/response in C#

To send SMS using the HTTP protocol, you only need to create a web request to the Ozeki Message Server. You can also receive the results of your request with a web response. In C# you can achieve this with a few lines of code:

// prepare the web page we will be asking for
String
   getUri = @"http://127.0.0.1:9333/ozeki?action=sendMessage&login=admin&
   password=abc123&recepient=" + recepient.ToString() + @"&messageData=" +
   message.ToString();

WebRequest request = (WebRequest)WebRequest.Create(getUri);
// execute the request
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

//read the response
StreamReader responseReader =
             new StreamReader(response.GetResponseStream());
String resultmsg = responseReader.ReadToEnd();
responseReader.Close();

You have to create a special HTTP request to the OZEKI Message Server, which listens on the 9333 port by default. This request starts with the hostname and the name of the port the Ozeki Server listens on (127.0.0.1:9333 in our example). You need to request a virtual page called ozeki and send it the parameters, depending on the action you intend to perform. For sending SMS messages you have to use:

action=sendMessage,
login=[admins login],
password=[admins password],
recepient=[phone number of the recepient],
messageData=[the message you wish to send].                     
                  

See more at : http://www.ozeki.hu/index.phtml?ow_page_number=654page_name=sms_HTTP_Server_SMS

After creating the request and calling the GetResponse() method on the request, the SMS Message will be sent, and you can optionally read the response. The response should look like this:

<Response>
      <Action>sendMessage</Action>
      <Data>
             &lt;AcceptReport&gt;
                &lt;StatusCode&gt;0&lt;/StatusCode&gt;
                &lt;StatusText&gt;Message accepted for
delivery&lt;/StatusText&gt;
                &lt;MessageID&gt;9294143&lt;/MessageID&gt;
             &lt;/AcceptReport&gt;
      </Data>
</Response>

Receiving SMS using HTTP request/response in C#

To receive SMS messages using HTTP, you need to start a simple web server which is very easy in C# on Windows XP, SP2 or Server 2003. First, you need to create a new HttpListener object using the constructor of the HttpListener class . Use the Prefixes property to gain access to a specific Uniform Resource Identifier (URI), which will be the base URL.
(Note: Prefixes have to end in a forward slash “/”.) Next, start this listener and write a callback method which will handle all requests to your server. The BeginGetContext() method begins an asynchronous (non-blocking) call to receive incoming client requests. For performance reasons, start 20 of them.

public class HttpServer
{
private HttpListener listener;

public HttpServer()
{
       listener = new HttpListener();
       listener.Prefixes.Add("http://127.0.0.1:9400/");//server url
       listener.Start();
       //Start 20 servers
       for (int x = 0; x < 20; x++)
       {
       listener.BeginGetContext(new AsyncCallback(ListenerCallback),
       this.listener);
       }
}

protected void ListenerCallback(IAsyncResult result)
{
       if (this.listener == null) return;
       HttpListenerContext context =
       this.listener.EndGetContext(result);
       //We setup a new context for the next request
       this.listener.BeginGetContext(new AsyncCallback(ListenerCallback),
       this.listener);
       this.ProcessRequest(context);
       context.Response.Close();
}

//Overridable method that can be used to implement a custom handler
protected virtual void ProcessRequest(HttpListenerContext context)
{
      string Sender = context.Request.QueryString["sender"];
      string Receiver = context.Request.QueryString["receiver"];
      string Msg = context.Request.QueryString["msg"];

      byte[] buffer =
System.Text.Encoding.UTF8.GetBytes("{SMS:TEXT}{}{+36205555224}
{+36201111245}{Thank you for the answer}" +
System.Environment.NewLine);
      context.Response.OutputStream.Write(buffer, 0, buffer.Length);
}
}

Once your web server receives a HTTP request, the callback (ListenerCallback()) function will be called. This method will end the asynchronous operation with the EndGetContext() and immediately start a new context for the next request. The ProcessRequest() method can now process the incoming request. Each parameter of the request can be accessed by its name. For example, the message data will be in context.Request.QueryString["msg"].
(Note: If you want the output to be displayed on a GUI, consider you are on another thread, so watch out for illegal cross-thread calls.) After your server has received a request, you should send back a response which looks like this:

"{SMS:TEXT}{}{[sender number]}{[recipient number]}{[message text]}"       

In the request the sender’s number is optional, but the recipient’s number and the message text are mandatory.





Next page: Access SMS