Software & Finance





Visual Studio.NET - Accessing Web Services From Visual C++ Client






Introduction

Creating the web reference from Visual Studio

Making web service to work under Secure HTTP protocol

To make it working under a proxy server




Introduction


In this section, I have explained how to use the web service from a Visual C++ client. In Visual C#, it is easy to implemment as Secure Protocl and Proxy support are inbuild where as in Visual C++, we have to use the library code provided along with ATL. To make it working under a firewall proxy server is just setting the proxy server name and the port number.

Top



Creating the web reference from Visual Studio


Creating a web reference from Visual Studio will generate an intermediate files to access the web service directly. You can find the files under the folder called web reference under your solution folder. You can see the header starting with "sproxy.exe generated file"

#pragma once
#if !defined(_WIN32_WINDOWS) &&
!defined(_WIN32_WINNT) &&
!defined(_WIN32_WCE)
#pragma message("warning: defining _WIN32_WINDOWS = 0x0410")
#define _WIN32_WINDOWS 0x0410
#endif

#include

namespace MyClientService
{

template >
class CMyClientServiceT : public TClient, public CSoapRootHandler
{

protected:

const _soapmap ** GetFunctionMap();
const _soapmap ** GetHeaderMap();
void * GetHeaderValue();
const wchar_t * GetNamespaceUri();
const char * GetServiceName();
const char * GetNamespaceUriA();
HRESULT CallFunction( void *pvParam, const wchar_t *wszLocalName, int cchLocalName, size_t nItem);
HRESULT GetClientReader(ISAXXMLReader **ppReader);

public:
HRESULT __stdcall QueryInterface(REFIID riid, void **ppv)
{
if (ppv == NULL)
{
return E_POINTER;
}
*ppv = NULL;

if (InlineIsEqualGUID(riid, IID_IUnknown) || InlineIsEqualGUID(riid, IID_ISAXContentHandler))
{
*ppv = static_cast(this);
return S_OK;
}
return E_NOINTERFACE;
}

ULONG __stdcall AddRef()
{
return 1;
}

ULONG __stdcall Release()
{
return 1;
}

CMyClientServiceT(const char *url, ISAXXMLReader *pReader = NULL) : TClient(url)
{
SetClient(true);
SetReader(pReader);
}

~CMyClientServiceT()
{
Uninitialize();
}

void Uninitialize()
{
UninitializeSOAP();
}

HRESULT GetUserName( int index, BSTR* GetUserCatalogSymbolListNameResult );

};

typedef CMyClientServiceT<> CMyClientService;

Top


Making web service to work under Secure HTTP protocol


You need to have two files called SecureHttp.h and SecureHttp.inl. It is a part of ATL - Active Template Library developed by Microsoft. You need to include the header file with #include "SecureHttp.h" The web service template code needs to changed to use Secure layer. You can do this by changing the code from

template > class CMyClientServiceT : public TClient, public CSoapRootHandler

to

template > class CMyClientServiceT : public TClient, public CSoapRootHandler

Top


To make it working under a proxy server


We can change the constructor in the following way to make our webservice client to work under proxy server.

CMyClientServiceT(const char *url, const char *proxy, int port, ISAXXMLReader *pReader = NULL) : TClient(url)
{
SetClient(true);
SetReader(pReader);
SetProxy(proxy, port);
}