SMS Gateway - Code Samples
XML Samples
The following XML samples outline the structure and fields present in the request
that is submitted to TextPort and the response that is received back to your calling
service. Enumerations for the country codes are listed
at the bottom of the page.
Contents of XML Request
<?xml version="1.0" encoding="utf-16"?>
<TextPortSMSMessages xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<UserName>your_username</UserName>
<Password>your_password</Password>
<Messages>
<TextPortSMSMessage>
<MessageText>Place the body of the text message in this field.</MessageText>
<CountryCode>US</CountryCode>
<MobileNumber>9505551212</MobileNumber>
</TextPortSMSMessage>
<TextPortSMSMessage>
<MessageText>This is the body of the second message in the request.</MessageText>
<CountryCode>US</CountryCode>
<MobileNumber>9365552121</MobileNumber>
</TextPortSMSMessage>
</Messages>
</TextPortSMSMessages>
Contents of XML Response
<?xml version="1.0" encoding="utf-16"?>
<TextPortSMSResponses xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ExtensionData />
<Responses>
<TextPortSMSResponse>
<ExtensionData />
<ErrorMessage />
<ItemNumber>1</ItemNumber>
<MessageID>444</MessageID>
<ProcessingMessage>Validating message request 1. Validation completed successfully. Message processed successfully.</ProcessingMessage>
<MobileNumber>9505551212</MobileNumber>
<Result>Success</Result>
</TextPortSMSResponse>
<TextPortSMSResponse>
<ExtensionData />
<ErrorMessage />
<ItemNumber>2</ItemNumber>
<MessageID>0</MessageID>
<ProcessingMessage>Validating message request 2. Validation completed successfully. Your message was not sent. The number 9365552121 was not recognized as a number handled by a mobile carrier.
</ProcessingMessage>
<MobileNumber>9365552121</MobileNumber>
<Result>Failed</Result>
</TextPortSMSResponse>
</Responses>
</TextPortSMSResponses>
Code Samples
Submit Messages Using the WCF Service (C#)
private void submitSMSToTextPort()
{
using (TextPortSMSService.TextPortSMSClient textPortSvc = new TextPortSMSService.TextPortSMSClient())
{
TextPortSMSService.TextPortSMSMessages messageList = new TextPortSMSService.TextPortSMSMessages()
{
UserName = "your_account_name_here ",
Password = "your_password_here",
Messages = new List<TextPortSMSService.TextPortSMSMessage>()
};
// Add first message
messageList.Messages.Add(new TextPortSMSService.TextPortSMSMessage()
{
CountryCode = "US",
MobileNumber = "5725551212",
MessageText = "Place the body of the text message in this field."
});
// Add second message
messageList.Messages.Add(new TextPortSMSService.TextPortSMSMessage()
{
CountryCode = "IN",
MobileNumber = "917365552121",
MessageText = "This message will be routed to India."
});
// Add more messages here...
// Submit the messages to the TextPort service
TextPortSMSService.TextPortSMSResponses responseList = textPortSvc.SendMessages(messageList);
foreach (TextPortSMSService.TextPortSMSResponse resp in responseList.Responses)
{
Console.WriteLine("Message #" + resp.ItemNumber.ToString() + " submitted with result " + resp.Result);
}
}
}
Submit Messages to the ASMX (SOAP) service using PHP
The following link demonstrates integration with the TextPort SMS web services using
PHP. (Sample provided courtesy of Matthew Watts).
https://github.com/mwatts7222/TextPort-PHP/blob/master/textPortConsume.php
ISO 2-character Country Codes
The values passed in the CountryCode property of the request must be one of the following:
| Country Name | Code |
| Afghanistan | AF |
| Albania | AL |
| Algeria | DZ |
| Angola | AO |
| Argentina | AR |
| Armenia | AM |
| Australia | AU |
| Austria | AT |
| Azerbaijan | AZ |
| Bahrain | BH |
| Bangladesh | BD |
| Barbados | BB |
| Belarus | BY |
| Belgium | BE |
| Belize | BZ |
| Bolivia | BO |
| Botswana | BW |
| Brazil | BR |
| Bulgaria | BG |
| Cambodia | KH |
| Cameroon | CM |
| Canada | CA |
| Cayman Islands | KY |
| Chad | TD |
| Chile | CL |
| China | CN |
| Colombia | CO |
| Comoros | KM |
| Costa Rica | CR |
| Croatia | HR |
| Cuba | CU |
| Cyprus | CY |
| Czech Republic | CZ |
| Denmark | DK |
| Djibouti | DJ |
| Ecuador | EC |
| Egypt | EG |
| El Salvador | SV |
| Equatorial Guinea | GQ |
| Estonia | EE |
| Ethiopia | ET |
| Fiji | FJ |
| Finland | FI |
| France | FR |
| Gabon | GA |
| Gambia | GM |
| Georgia | GE |
| Germany | DE |
| Ghana | GH |
| Greece | GR |
| Greenland | GL |
| Guam | GU |
| Guatemala | GT |
| Guinea | GN |
| Guyana | GY |
| Haiti | HT |
| Honduras | HN |
| Hong Kong | HK |
| Hungary | HU |
| Iceland | IS |
| India | IN |
| Indonesia | ID |
| Iran | IR |
| Iraq | IQ |
| Ireland | IE |
| Israel | IL |
| Italy | IT |
| Jamaica | JM |
| Japan | JP |
| Jordan | JO |
| Kazakhstan | KZ |
| Kenya | KE |
| Korea | KR |
| Kuwait | KW |
| Kyrgyzstan | KG |
| Laos | LA |
| Latvia | LV |
| Lebanon | LB |
| Lesotho | LS |
| Liberia | LR |
| Lithuania | LT |
| Luxembourg | LU |
| Madagascar | MG |
| Malaysia | MY |
| Mauritius | MU |
| Mexico | MX |
| Monaco | MC |
| Mongolia | MN |
| Morocco | MA |
| Mozambique | MZ |
| Nepal | NP |
| Netherlands | NL |
| New Zealand | NZ |
| Nicaragua | NI |
| Niger | NE |
| Nigeria | NG |
| Norway | NO |
| Oman | OM |
| Pakistan | PK |
| Panama | PA |
| Paraguay | PY |
| Peru | PE |
| Philippines | PH |
| Poland | PL |
| Portugal | PT |
| Puerto Rico | PR |
| Qatar | QA |
| Romania | RO |
| Russia | RU |
| Rwanda | RW |
| Samoa | WS |
| San Marino | SM |
| Saudi Arabia | SA |
| Senegal | SN |
| Serbia | RS |
| Seychelles | SC |
| Sierra Leone | SL |
| Singapore | SG |
| Slovakia | SK |
| Slovenia | SI |
| Somalia | SO |
| South Africa | ZA |
| Spain | ES |
| Sri Lanka | LK |
| Sudan | SD |
| Suriname | SR |
| Swaziland | SZ |
| Sweden | SE |
| Switzerland | CH |
| Syria | SY |
| Taiwan | TW |
| Tanzania | TZ |
| Thailand | TH |
| Togo | TG |
| Tonga | TO |
| Trinidad and Tobago | TT |
| Turkey | TR |
| Turkmenistan | TM |
| Uganda | UG |
| Ukraine | UA |
| United Arab Emirates | AE |
| United Kingdom | GB |
| Uruguay | UY |
| USA | US |
| Uzbekistan | UZ |
| Vanuatu | VU |
| Venezuela | VE |
| Vietnam | VN |
| Virgin Islands, British | VG |
| Yemen | YE |
| Zambia | ZM |
| Zimbabwe | ZW |