Using SOAP web services in the .Net framework is extremely simple. First,
add a web reference to your project which points to the above URL. All of the necessary
code for parsing messages and responses will be added to the project. Sending an
SMS message then consists of two lines of code: (assuming the required imports
or using statements are present)
SendSMS SMSMessenger = new SendSMS();
result = SMSMessenger.SendMessage(CellNumber, MessageBody, AccountKey);
If you prefer to use REST and JSON in .Net rather than Soap and XML, you can use the WebClient class and a JSON deserializer such as JSON. Net to do the following:
string url = string.Format("http://smsgateway.ca/services/message.svc/{1}/{0}", recipientCellNumber, accountKey);
var serviceRequest = new WebClient();
serviceRequest.Headers[HttpRequestHeader.ContentType] = "application/JSON";
string jsonStringParams = string.Format("{{\"MessageBody\":\"{0}\",\"Reference\":\"{1}\"}}", messageBody, reference);
var response = serviceRequest.UploadString(url, "POST", jsonStringParams);
var jsonObject = JObject.Parse(response);
string response = (string) jsonObject["SendMessageWithReferenceResult"];
Download Samples (.Net Framework 2.0, Visual Studio 2005)
Download Samples (.Net Framework 4.5, Visual Studio 2012)
PHP 5 SOAP Module Sample Code (Requires installation of the SOAP Module)
class SMSParam {
public $CellNumber;
public $AccountKey;
public $MessageBody;
}
$client = new SoapClient('http://www.smsgateway.ca/sendsms.asmx?WSDL');
$parameters = new SMSParam;
$parameters -> CellNumber = "212-555-1212";
$parameters -> AccountKey = "GSP1234567";
$parameters -> MessageBody = "This is a demonstration of SMSGateway.ca using PHP5.";
$Result = $client->SendMessage($parameters);
Download Samples
- PHP Samples - Includes samples using NuSoap
and the SOAP module in PHP 5. Please note that we do not recommend the NuSoap library
for our more advanced functions, as the handling of arrays in NuSoap is not compatible
with the latest SOAP standard.
We strongly recommend making using of the free Microsoft SOAP Toolkit. This toolkit contains a COM object
which allows you to make SOAP calls in three simple steps.
- First, create an instance of an MSSoap.SoapClient30 object.
- Initialize the instance by calling the mssoapinit method and passing in
the URL of the webservice.
- Call the SendMessage or SendMessageWithReference method on the
object.
Here is an example in Visual Basic 6:
Set SMSMessenger = CreateObject("MSSoap.SoapClient30")
Call SMSMessenger.mssoapinit("http://www.smsgateway.ca/SendSMS.asmx?wsdl")
Dim result As String
result = SMSMessenger.SendMessage(CellNumber, MessageBody, AccountKey)
The SOAP Toolkit 3.0 can be downloaded here
Download Samples
|