SMS API
Quick Start: C#
There are three steps to integrating our programmable SMS API into your Visual Studio C# project.
1. Create an account.
Sign up for an account. When you register you will receive a license key to send messages from. You will need this to use the API.
2. Add a web service reference to your project.
In order to call the SMS API, you will need to create a project with a web service reference.
Start by creating a new Console App project in Visual Studio. Then, in the Solution Explorer, right click on your project and select Add > Service Reference….
Visual Studio will open an “Add service reference” dialog. Select WCF Web Service and click the Next button.
In the URI field, type in the URL for the SMS service description file: https://messaging.esendex.us/messaging.svc?wsdl. Then click the Go button.
Once the wizard has successfully contacted the SMS API service, the service will be shown below the URL.
Change the Namespace to something appropriate for your project. Let’s call it WSDL.
Click the Next button. Visual Studio will offer some options for customizing the service, but you can leave these as default.
The wizard will add the service to your project’s service references (as shown).
3. Send a test message.
Add your code to the “Program.cs” file. Here is a simple example that sends a message using the SendMessage
method.
Replace the LicenseKey
value with your account’s license key.
Replace the To
value with your own mobile phone number.
using WSDL;
var client = new MessagingClient(
MessagingClient.EndpointConfiguration.mms2wsHttpBindingSecure);
var request = new OutgoingMessageRequest
{
Body = "Hi, this message was sent using C#.",
LicenseKey = new("00000000-0000-0000-0000-000000000000"),
To = new[] { "7575559999" }
};
var messages = await client.SendMessageAsync(request);
foreach (var m in messages)
{
Console.WriteLine(
"Message ID: " + m.MessageID + Environment.NewLine +
"Message Status: " + m.MessageStatus + Environment.NewLine +
"To: " + m.To + Environment.NewLine +
"From: " + m.From + Environment.NewLine +
"UTC Time Sent: " + m.SentTime + Environment.NewLine);
}
Run the project. Visual Studio will open a debug console. If the message status says Ready, your call to the API was a success! You will receive the text message shortly on your phone.
Message ID: 1627aea5-8e0a-4371-9022-9b504344e724
Message Status: Ready
To: 17575559999
From: 17575550000
UTC Time Sent: 5/3/2023 3:59:02 PM
Let’s start sending, together.