Connecting to the TextPort SMS Gateway Using .NET 2.0 Web Services (ASMX)


This tutorial outlines how to set up a .NET 2.0 ASMX web service in Microsoft Visual Studio 2010 or 2008. Although web services 2.0 is fully supported, it has been replaced with Microsoft WCF (Windows Communication Foundation) services. Here is a tutorial for interfacing using WCF.



Step 1 – In your Visual Studio project Solution Explorer, locate the Service References item. Right click to display the menu, then click the Add Service Reference option.

step1

Step 2 – In the Add Service Reference dialog, click the Advanced button at the bottom of the window. This displays the dialog for advanced settings. This will open the dialog for adding a 2.0 web service reference. If you are using Visual Studio 2005 or 2008, these steps may differ slightly, but the dialogs are all the same.

Note: It is also possible to set the ASMX service up as a service reference instead of a web reference. For the sake of simplicity, we have not documented this approach, but if you are familiar with web services, the configuation is straight-forward. Refer to the WCF tutorial and replace the WCF service with the ASMX service if you want to try this option.

step2

Step 3 – Click the Add Web Reference button. This displays the dialog that allows you to add a .NET 2.0 web reference (non WCF service).

step3

Step 4 – Enter the URL of the TextPort ASMX (.NET 2.0 Web service) in the URL field, then click the green arrow button to the right of this field. The web service will be fetched. Next, give your web service a name (e.g. TextPortSMSWebService) and click Add Reference.

step4

Your solution explorer should now display the web reference like this:

step5

Step 5 – Write some code to send two test messages. The code below can be copied and pasted into your project. Replace the username, password, mobile numbers and message text with values that are relevant to your account and mobile devices.

                        public void SubmitSMSToTextPort_WebService()
                        {
                            using (TextPortSMSWebService.SMSClient textPortWebService = new TextPortSMSWebService.SMSClient())
                            {
                                TextPortSMSWebService.TextPortSMSMessages messageList = new TextPortSMSWebService.TextPortSMSMessages()
                                {
                                    UserName = "your_username_here",
                                    Password = "your_password_here",
                                    Messages = new TextPortSMSWebService.TextPortSMSMessage[2]
                                };

                                // Add first message
                                messageList.Messages[0] = new TextPortSMSWebService.TextPortSMSMessage()
                                {
                                    CountryCode = "US",
                                    MobileNumber = "9495551212",
                                    MessageText = "This is test message number 1"
                                };

                                // Add second message
                                messageList.Messages[1] = new TextPortSMSWebService.TextPortSMSMessage()
                                {
                                    CountryCode = "US",
                                    MobileNumber = "5105551010",
                                    MessageText = "This is the second test message"
                                };

                                // Submit the messages to the TextPort service
                                TextPortSMSWebService.TextPortSMSResponses responseList = textPortWebService.SendMessages(messageList);

                                foreach (TextPortSMSWebService.TextPortSMSResponse resp in responseList.Responses)
                                {
                                    Console.WriteLine("Message #" + resp.ItemNumber.ToString() + " submitted with result " + resp.Result);
                                }
                            }
                        }
                    

Execute the code above and the messages will be sent.