Send Free SMS - Web Service

July 17th, 2008

27/Sep/2008 - Important Update 3: The web service has been updated yet again. If you are using the script on your own server, then please download the zip file again. Extract this zip file in the same place where sendsms.php is currently located and you should be good to go.


02/Sep/2008 - Important Update 2: The web service has been updated. If you are using the script on your own server, then please download the zip file again. Extract this zip file in the same place where sendsms.php is currently located. The zip file now contains an extra file named “htmlparser.inc” (version 1.2) from PHP HTML Parser. It’s an awesome library to parse HTML using PHP.


Important Update: After this comment from cssk, the web service has been updated. If you are using the script on your own servers, please download it again from here and just replace the existing file. Others, who are just accessing the URL on my domain needn’t make any changes to their code.


Hi friends, if you are in India and if you are developing software prototypes which has to send SMS alerts to various Indian mobile numbers, you needn’t spend a lot to buy SMS credits at the various sites. Over the last weekend, I spent some time hacking up a quick SOAP based web service which you can consume in your programs.

Before we proceed further, here are a few things you have to do:

  1. Get an account at http://www.way2sms.com/. Its a free SMS service and has tons of advantages; including 92 characters per message (rest of the characters are ads) and unlimited number of messages per day.
  2. Now you can invoke the web service in two ways from my domain itself. Web service endpoints and other notes given below.
  3. You can get the PHP source code and set it up in your own server.

Invoking the Web Service:

  1. The web service end point is at http://www.aswinanand.com/sendsms.php?wsdl. More details on how to consume a web service using Visual Studio is available here. Feel free to try with other languages and IDEs and let me know.
  2. Instead of consuming the web service, you can invoke the URL directly with the four parameters. Parameters are:
    • uid = your way2sms user id
    • pwd = your way2sms password
    • phone = semicolon separated list of phone numbers
    • msg = actual text message
  3. An example URL format is http://www.aswinanand.com/sendsms.php?uid=__USER_ID__&pwd=__PWD__&phone=__NUMBER__&msg=__MSG__.

Setting up the web service in your hosting space:

  1. Grab the SMS web service source code from here. The source code is licensed under “Creative Commons Attribution-Noncommercial”. Make sure you agree to the license terms before downloading :-) and kindly link back here or digg it.
  2. Get the NuSoap library and upload it to your server. You may want to change line number 50 in our web service source code to point to the proper location of NuSoap on your server.
  3. Now as mentioned in the section above, you can now use the web service from your domain. Just replace “http://www.aswinanand.com/” with “http://www.your-domain.com/path/to/source/” and you should be good to go on your own :D

Improvements:

Of course, there are lots of improvements that can be made to this service. Way2SMS console gives you a list of all the messages that have been sent from your account so far. So, you could write another web method and expose it; which returns all the messages so far in the form of RSS feed, ATOM feed or JSON.

Any text after the 92nd character in the SMS is cut off. We could write a simple loop after line 36 to send multiple messages if the number of characters exceeds 92.

We should also be able to retrieve the list of contacts that are saved in Way2SMS as JSON feeds and reuse them to send messages instead of typing in mobile numbers directly.

I will update the script as and when time permits and update this space. Keep watching for more. This sort of web services can be developed for almost all SMS web sites. If you are developing a similar script for other SMS websites, let me know.

Some boring blah blahs:

  1. The code is not production grade. It was hacked quickly over a weekend. So use it at your own risk.
  2. You cannot hold me responsible for whatever problems that may occur for you in using this web service.

You could also do me a small favour by digging this post. Thanks!

hi!! guys, yesterday i developed a simple “Hello World!” webservice with java. With Netbeans 5.0 IDE its a breeze to create web services. It comes bundled with Apache Tomcat 5.5.9 and Sun Java Application Server 8.2.

You can find the quickstart tutorial here to develop web services. Just follow that tute and you will be fine. I will tell you how to consume the same using .net. I used Visual Studio 2005 to consume this service. I assume that you have the url for the wsdl of the webservice which should be similar to, http://localhost:8080/WebApplication1/NewWebService?WSDL.

1. Open Visual studio. “File->New->Website”. If using VS2003 then, “File->New->Project->ASP.NET Web Application”.
2. A web application should have been created by now and you have the “design view” of “default.aspx” or any other aspx page of your choice.
3. Press Ctrl+Alt+L or View->Solution Explorer. Right click on your project name and select “Add Web Reference”. In the windows that pops up, give the WSDL url and an “Instance Name”. My instance name was “JavaAdd”.
4. Add a button and a label to the asp.net page. Double click the button and paste the following code.

VB.NET
Dim js As New JavaAdd.NewWebService()
Dim myadd As New JavaAdd.add()
Dim myaddRes As New JavaAdd.addResponse()
myadd.int_1 = 10
myadd.int_2 = 10
myaddRes = js.add(myadd)
Label1.Text = myaddRes.result

C#

JavaAdd.NewWebService js = new JavaAdd.NewWebService();
JavaAdd.add myadd = new JavaAdd.add();
JavaAdd.addResponse myaddRes=new JavaAdd.addResponse(); myadd.int_1=10;
myadd.int_2=10;
myaddRes=js.add(myadd); Label1.Text=Convert.ToString(myaddRes.result);

Instead of “sayHi” method in the quickstart tute, i created a method called “add” which accepts 2 integer parameters and returns an integer after adding them up.

5. Press F5 now. You should get something similar to these.

Thats it for this post…bye!