Sample - VB.NET

Web Service

There are two ways we can suggest to connect to the TextAnywhere Web Service with VB.NET. 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:

Dim ta_sms = New net.textanywhere.ws.TextAnywhere_SMS Dim 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 imports System.Net):

Dim proxyObject = New WebProxy("proxy_server", 8080) 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.vb 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:

Dim ta_sms = New TextAnywhere_SMS() Dim 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 imports System.Net):

Dim proxyObject = New WebProxy("proxy_server", 8080) 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 VB.NET. 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:

Dim ta_sms_rb = New net.textanywhere.ws.TA_SMS_RB() Dim 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 imports System.Net):

Dim proxyObject = New WebProxy("proxy_server", 8080) proxyObject.Credentials = New NetworkCredential("username", "password") ta_sms.Proxy = proxyObject

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

Dim ta_sms_rb = New net.textanywhere.ws.TA_SMS_RB() Dim 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.vb 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:

Dim ta_sms_rb = New TA_SMS_RB() Dim 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 imports System.Net):

Dim proxyObject = New WebProxy("proxy_server", 8080) proxyObject.Credentials = New NetworkCredential("username", "password") ta_sms.Proxy = proxyObject

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

Dim ta_sms_rb = New TA_SMS_RB() Dim 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 imports System.Net, imports System.IO and imports System.Text for these to work.

Dim 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") Dim response As WebResponse = http_request.GetResponse() Dim reader = New StreamReader(response.GetResponseStream()) Dim result = reader.ReadToEnd() response.Close()

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

Dim proxyObject = New WebProxy("proxy_server", 8080) 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:

Dim 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" Dim query_data = Encoding.UTF8.GetBytes(query_string) Dim http_request As WebRequest = 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 Dim request_stream = http_request.GetRequestStream() request_stream.Write(query_data, 0, query_data.Length) Dim response As WebResponse = http_request.GetResponse() Dim reader = New StreamReader(response.GetResponseStream()) Dim 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 imports System.Web and also adding a reference to System.Web.dll version 2.0:

Dim ctx As New HttpContext(Nothing) Dim body = ctx.Server.UrlEncode("hello world")

Footer Bottom