Thursday, January 03, 2008

Esendex Webservice SMS using C++

C++ is not my main language, but all Esendex developers are expected to help our customers integrate their systems with ours on top of our usual development work.

Admittedly we don't have many people asking for help with C++, but when they do we usually direct them to the C++ SMS SDK. This includes a COM component which developers must install, and this fact does pose some problems for some developers.

So, while waiting for a build I found How to Consume [a] WebService via unmanaged C++, which describes how you can get Visual Studio 2005 (and apparently 2003 as well, but I've not checked that), to generate a proxy for you.

In Visual Studio 2005:

1. Generate the proxy:

  1. Right click on the project in the Solution Explorer and click Add Web Reference.
  2. In the dialog, enter http://www.esendex.com/secure/messenger/soap/SendServiceNoHeader.asmx as the URL, and give it a name
  3. Click Add Web Reference
  4. This will generate a file in your project (with the name you gave it)
2. Write code to call the proxy:

SendServiceNoHeader::CSendServiceNoHeader proxy;
BSTR result = NULL;
HRESULT hr = proxy.SendMessageFull( CComBSTR("username"),
CComBSTR("password"),
CComBSTR("account reference"),
CComBSTR("originator"),
CComBSTR("destination"),
CComBSTR("C++ Hello!"),
CComBSTR("Text"), 0, &result);
3. Notes:
  1. result will contain the ID of the message you've just sent
  2. hr can be used to check if the operation was successful
  3. You may need to include the line CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); before this code if your application doesn't already have it.

No comments: