Creating a Client in C++ Using ATL Server
This section explains how to create an ATL Server web service client for the AAA Server 6.7.2 SKI Connector service.
Differences between Microsoft Visual Studio 2005 and 2008:
The following are no longer included in Microsoft Visual Studio 2008:
-
ATL Server technology – you should either compile the sample code using Microsoft Visual Studio 2005, or include the ATL Server library headers in the project.
-
The sproxy.exe tool used to generate the web service files – use the version provided in Microsoft Visual Studio 2005.
Generate the Web Service Client Files
Use the following command line to run sproxy.exe and generate the header file containing all the classes and structures required to use the web service:
sproxy.exe /wsdl /out:<output_path>\SKIConnector.h <wsdl_path>\ActivCardSKIConnectorV2.wsdl
Where:
-
<output_path> points to the folder where the generated files are to be stored.
-
<wsdl_path> points to the folder of the .wsdl file.
The same also applies to the .wsdl file: It is not necessary to include it in the project, but take into account that some tools might generate classes according to the filename.
Configure the Web Service Client
-
Use the following command to initialize the COM objects used by the ALT Server:
CoInitialize(NULL);
-
Include the generated .h file in the project and use the namespace given by the generated file to access the client classes and functions.
In the provided .wsdl file, the namespace should be ActivCardSKIConnectorV2.
-
The generated header contains a class in charge of generating an instance of the client (in the sample, CActivCardSKIConnectorV2T<CSoapMSXMLInetClient>).
To create a client, generate an instance of this class as follows:
CActivCardSKIConnectorV2T<CSoapMSXMLInetClient> * pService;
pService = new CActivCardSKIConnectorV2T<CSoapMSXMLInetClient>;
-
As the sample does not use SSL, configure the client with the following elements:
- pService->SetTimeout(timeout); – A timeout in milliseconds.
- pService->SetUrl(url); – The service endpoint URI in a TCHAR table.
-
For AAA Server 6.7.2, set the service endpoint URI as follows:
http://<hostname>:<port>/Invoke?Handler=ActivCardSKIConnectorV2
-
To test the client configuration and connection, it is recommended that you use a simple function such as getVersion().
If getVersion() returns nothing or indicates an error, the endpoint URL might be wrong or using an invalid format.
Use the ActivID SKI Connector Functions
-
To use the ActivID SKI Connector functions, call the corresponding methods of the client with the required variables.
For further information about the method names and input/output variables, refer to ActivID SKI Connector Service API Functions.
-
As most functions can only be used with a valid login handle, retrieve it using the Login() function before performing any other operation.
-
As ATL server is using COM object, allocate each String passed as an argument with SysAllocString() and free them with SysFreeString().
-
If the function has an output value, pass a reference or pointer to a relevant variable to retrieve it.
If the returned value is a structure, it should be one that is defined in the generated header file.
Closing the Service
-
Before closing the service, it is recommended that you use the Logout() function to invalidate the login handle.
If you do not, it is only invalidated after a defined time (10 minutes).
-
To close the server, delete the instance of the class as follows:
Copydelete pService;
pService = NULL;
CoUninitialize();
Error Cases
With the ATL Server API, all client function calls return an HRESULT indicating if the web service call performed correctly.
In addition, most functions have a returned value (often a boolean) indicating if the operation was successful.
Implementation Example
int nTimeout = 10 * 60 * 1000; /* setting a 10 minutes timeout */
HRESULT hRes = S_FALSE;
long long hLogin = -1;
BSTR sTMPadminUID = SysAllocString("<admin_uid>");
BSTR sTMPadminPWD = SysAllocString("<admin_pwd>");
hRes = pService->Login( sTMPadminUID,
sTMPadminPWD,
nTimeout,
&hLogin);
SysFreeString(sTMPadminUID);
SysFreeString(sTMPadminPWD);
if (SUCCEEDED(hRes))
{
if (hLogin>0) cout << "Login succeeded."<< endl;
else
{
cout << "ERROR: invalid credentials." << endl;
// Handle error case
}
}
else
{
cout << "ERROR: Login webservice call failed" << endl;
// Handle error case
}