Listing 1
#include <iostream>
#include <tchar.h>
#include "Windows.h"
#include "WinInet.h"
using namespace std;
void BuildSoapRequest(TCHAR* pszSoap)
{
_tcscpy(pszSoap, _T("") );
_tcscat(pszSoap,
_T("<soap:Envelope
xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">") );
_tcscat(pszSoap, _T("<soap:Header>") );
_tcscat(pszSoap, _T("</soap:Header>") );
_tcscat(pszSoap, _T("<soap:Body>") );
_tcscat(pszSoap, _T("<GetVersionInfo
xmlns=\ "http://s.mappoint.net/mappoint-30/\">") );
_tcscat(pszSoap, _T("</GetVersionInfo>") );
_tcscat(pszSoap, _T("</soap:Body>") );
_tcscat(pszSoap, _T("</soap:Envelope>") );
}
int _tmain(int argc, _TCHAR* argv[])
{
LPTSTR AcceptTypes[2] = {TEXT("text/xml"), NULL};
DWORD dwFlags = INTERNET_FLAG_RELOAD |
INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_KEEP_CONNECTION;
HINTERNET hNet = InternetOpen("SpikeApp", INTERNET_OPEN_TYPE_PRECONFIG,
NULL, NULL, 0);
if (hNet)
{
wcout << L"Opened Internet connection and got valid handle" << endl;
HINTERNET hSession = InternetConnect(hNet,
_T("findv3.staging.mappoint.net"),
INTERNET_DEFAULT_HTTP_PORT, _T("<username>"), _T("<password>"),
INTERNET_SERVICE_HTTP, 0, 0);
if (hSession)
{
wcout << L"Opened session for WS and got valid handle" << endl;
HINTERNET hRequest = HttpOpenRequest(hSession, _T("POST"),
_T("/Find-30/Common.asmx"), HTTP_VERSION,
NULL, (LPCTSTR*)AcceptTypes, dwFlags, 0);
if (hRequest)
{
wcout << L"Opened Request for WS & got valid handle" << endl;
TCHAR szSoapAction[256];
_tcscpy( szSoapAction, _T("Content-Type: text/xml;
charset=utf-8\n") );
_tcscat( szSoapAction, _T("SOAPAction: \"") );
_tcscat( szSoapAction, _T
("http://s.mappoint.net/mappoint-30/GetVersionInfo") );
_tcscat( szSoapAction , _T("\"\0") );
TCHAR szSoap[512];
BuildSoapRequest(szSoap);
BOOL bSent = HttpSendRequest(hRequest, szSoapAction,
_tcslen(szSoapAction), szSoap, _tcslen(szSoap) );
if ( bSent )
{
CHAR* lpBufferA = new CHAR[32000];
DWORD dwcBuffer;
if (!InternetReadFile (hRequest,
(LPVOID)lpBufferA, 32000, &dwcBuffer))
{
wcout << L"Failed to read response" << endl;
}
else{
CHAR* szResponse = new CHAR[dwcBuffer + 1];
strncpy(szResponse,lpBufferA, dwcBuffer);
wcout << L"Response" << endl << szResponse << endl;
delete [] szResponse;
}
delete [] lpBufferA;
}
else{
DWORD dwErr = GetLastError();
wcout << L"Send Request Failed. Error:" << dwErr << endl;
}
InternetCloseHandle(hRequest);
}
InternetCloseHandle(hSession);
}
InternetCloseHandle(hNet);
}
return 0;
}