Samples - C#

The samples below require the .NET Framework 2.0

Web Service

There are two ways we can suggest to connect to the TextAnywhere Web Service with C#. The first, using Visual Studio is straight forward. Right-click your project and select ‘Add a web reference’. Into the URL field enter https://ws.textanywhere.net/TA_SMS.asmx?wsdl, and then click the ‘Go’ button. You should see the TextAnywhere_SMS page, if so, click ‘Add Reference’. If you do not see the TextAnywhere_SMS page you should check your Internet Explorer proxy settings or speak to your network administrator.

Assuming you did not change the contents of the ‘Web Reference Name’ field, you would be able to send a message:

net.textanywhere.ws.TextAnywhere_SMS ta_sms = new net.textanywhere.ws.TextAnywhere_SMS(); string result = ta_sms.SendSMSEx("my_id", "my_pass", "my_ref", "billing_ref", 2, "+447912345678", 0, "+447923456789", "hello world", 0, 0, "");

You can call any of the other Web Service methods in a similar manner. In most cases, Visual Studio will bring up a list of available methods when you type ‘ta_sms.’. If you need to specify proxy settings, you can set the properties of the TextAnywhere_SMS object (REQUIRES using System.Net;):

IWebProxy proxyObject = new WebProxy("proxy_server", "proxy_port"); proxyObject.Credentials = new NetworkCredential("username", "password"); ta_sms.Proxy = proxyObject;

If you cannot use Visual Studio, it is still possible to use the wsdl.exe command line utility to generate the TextAnywhere_SMS object code. The utility is part of the 2.0 .NET framework SDK. You can download this from Microsoft . To create the object code you would navigate to the ‘Bin’ folder of the SDK and execute the following command:

This will produce a file called TextAnywhere_SMS.cs in the SDK ‘Bin’ folder. You can incorporate this file into your project, and then use the TextAnywhere_SMS object from within your own code:

TextAnywhere_SMS ta_sms = new TextAnywhere_SMS(); string result = ta_sms.SendSMSEx("my_id", "my_pass", "my_ref", "billing_ref", 2, "+447912345678", 0, "+447923456789", "hello world", 0, 0, "");

If you need to specify proxy details you can do so as required (REQUIRES using System.Net;):

IWebProxy proxyObject = new WebProxy("proxy_server", "proxy_port"); proxyObject.Credentials = new NetworkCredential("username", "password"); ta_sms.Proxy = proxyObject;

TextPremium Web Service

There are two ways we can suggest to connect to the TextAnywhere TextPremium Web Service with C#. The first, using Visual Studio is straight forward. Right-click your project and select ‘Add a web reference’. Into the URL field enter https://ws.textanywhere.net/ws_textpremium/TA_WS_RB.asmx, and then click the ‘Go’ button. You should see the TA_SMS_RB page, if so, click ‘Add Reference’. If you do not see the TA_SMS_RB page you should check your Internet Explorer proxy settings or speak to your network administrator.

Assuming you did not change the contents of the ‘Web Reference Name’ field, you would be able to retrieve received messages:

net.textanywhere.ws.TA_SMS_RB ta_sms_rb = new net.textanywhere.ws.TA_SMS_RB(); string result = ta_sms_rb.ReadTextMT("my_id", "my_pass", "shortcode_keyword");

You can call any of the other TextPremium Web Service methods in a similar manner. In most cases, Visual Studio will bring up a list of available methods when you type ‘ta_sms_rb.’. If you need to specify proxy settings, you can set the properties of the TA_SMS_RB object (REQUIRES using System.Net;):

IWebProxy proxyObject = new WebProxy("proxy_server", "proxy_port"); proxyObject.Credentials = new NetworkCredential("username", "password"); ta_sms_rb.Proxy = proxyObject;

To send charged messages in response to your incoming messages you would use the SendMTResponse method:

net.textanywhere.ws.TA_SMS_RB ta_sms_rb = new net.textanywhere.ws.TA_SMS_RB(); string result = ta_sms_rb.SendMTResponse("my_id", "my_pass", "my_ref", "RBID", "hello world");

If you cannot use Visual Studio, it is still possible to use the wsdl.exe command line utility to generate the TA_SMS_RB object code. The utility is part of the 2.0 .NET framework SDK. You can download this from Microsoft. To create the object code you would navigate to the ‘Bin’ folder of the SDK and execute the following command:

This will produce a file called TA_SMS_RB.cs in the SDK ‘Bin’ folder. You can incorporate this file into your project, and then use the TA_SMS_RB object from within your own code. To retrieve incoming premium messages:

TA_SMS_RB ta_sms_rb = new TA_SMS_RB(); string result = ta_sms_rb.ReadTextMT("my_id", "my_pass", "shortcode_keyword");

If you need to specify proxy details you can do so as required (REQUIRES using System.Net;):

IWebProxy proxyObject = new WebProxy("proxy_server", "proxy_port"); proxyObject.Credentials = new NetworkCredential("username", "password"); ta_sms_rb.Proxy = proxyObject;

To send charged messages in response to your incoming messages you would use the SendMTResponse method:

TA_SMS_RB ta_sms_rb = new TA_SMS_RB(); string result = ta_sms_rb.SendMTResponse("my_id", "my_pass", "my_ref", "RBID", "hello world");

HTTP(S) Service

Connecting to the HTTP(S) Service is very straightforward. You have the option to use HTTP(S) POST and GET methods. You can find the general formula for creating the URIs in the HTTP(S) Service documentation.

Firstly, you will need a System.Net; and using System.IO; for these to work.

WebRequest http_request = WebRequest.Create("https://ws.textanywhere.net/HTTPRX/SendSMSEx.aspx?Client_ID=my_id&Client_Pass=my_pass&Client_Ref=my_ref&Billing_Ref=billing_ref&Connection=2&Originator=%2b447912345678&OType=0&DestinationEx=%2b447923456789&Body=hello%20world&SMS_Type=0&Reply_Type=0"); WebResponse response = http_request.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream()); string result = reader.ReadToEnd(); response.Close();

If you need to specify proxy details you can do so:

IWebProxy proxyObject = new WebProxy("proxy_server", "proxy_port"); proxyObject.Credentials = new NetworkCredential("username", "password"); http_request.Proxy = proxyObject;

You will of course need to specify them before the call to GetResponse().

So, to use the HTTP(S) POST method, your code will look like this:

string query_string = "Client_ID=my_id&Client_Pass=my_pass&Client_Ref=my_ref&Billing_Ref=billing_ref&Connection=2&Originator=%2b447912345678&OType=0&DestinationEx=%2b447923456789&Body=hello%20world&SMS_Type=0&Reply_Type=0"; byte[] query_data = Encoding.UTF8.GetBytes(query_string); WebRequest http_request = WebRequest.Create("https://ws.textanywhere.net/HTTPRX/SendSMSEx.aspx"); http_request.Method = "POST"; http_request.ContentType = "application/x-www-form-urlencoded"; http_request.ContentLength = query_data.Length; Stream request_stream = http_request.GetRequestStream(); request_stream.Write(query_data, 0, query_data.Length); WebResponse response = http_request.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream()); string result = reader.ReadToEnd(); response.Close();

Remember, all parameter values need to be URL encoded no matter which HTTP(S) method (GET or POST) you choose. This will require a using System.Web; and also adding a reference to System.Web.dll version 2.0:

HttpContext ctx = new HttpContext(null); string body = ctx.Server.UrlEncode("hello world");

Footer Bottom