Windows Source-Code Demos
CalcSslClient.cpp
//===============================================================================================================================
// title: CalcSslClient.cpp
// author: Neil Rieck (adapted from "//gsoap/gsoap/samples/calc++/calcclient.cpp")
// created: 2013-07-28
// os: Windows-7
// target: gSOAP for Windows
// compiler: Microsoft Visual C++ 2010 Express (a.k.a. MSVC 2010)
// C/C++: General >> Additional Include Directories: add C:\OpenSSL-Win32\include;
// Preprocessor >> Definitions: add WITH_OPENSSL;
// Linker: General >> Additional Library Directories: add C:\OpenSSL-Win32\lib;
// Input >> Additional Dependencies: add libeay32.lib;ssleay32.lib;
// (if MSVC6 then) also add ws2_32.lib;
// Caveat: When building a Win32 Console app on 64-bit Windows-7 you must link against the 32-bit version of gSOAP
// On my 64-bit system, I have installed both the 32-bit and 64-bit versions of gSOAP which I downloaded from here:
// http://www.slproweb.com/products/Win32OpenSSL.html (very high quality work; donate a few bucks if you can)
// 1) one version was placed here: c:\OpenSSL-Win32\
// 2) the other version went here: c:\OpenSSL-Win64\
//===============================================================================================================================
#include "soapcalcProxy.h"
#include "calc.nsmap"
#ifdef WITH_OPENSSL
const char server[] = "https://142.180.39.16/gsoap_calc_server"; // works with MOD_GSOAP (Apache) on port 443
#else
const char server[] = "http://142.180.39.16/gsoap_calc_server"; // works with MOD_GSOAP (Apache) on port 80
#endif
int main(int argc, char **argv)
{ printf("-i-server: %s\n", server);
if (argc < 4)
{ fprintf(stderr, "Usage: [add|sub|mul|div|pow] num num\n");
exit(0);
}
double a, b, result;
a = strtod(argv[2], NULL);
b = strtod(argv[3], NULL);
calcProxy calc;
calc.soap_endpoint = server;
#ifdef WITH_OPENSSL
printf("-i-calling: soap_ssl_init()\n");
soap_ssl_init();
printf("-i-calling: soap_client_context()\n");
if (soap_ssl_client_context(
&calc,
SOAP_SSL_NO_AUTHENTICATION,
NULL,
NULL,
NULL,
NULL,
NULL))
{
soap_print_fault(&calc, stderr);
exit(1);
}
#endif
switch (*argv[1])
{ case 'a':
calc.add(a, b, &result);
break;
case 's':
calc.sub(a, b, &result);
break;
case 'm':
calc.mul(a, b, &result);
break;
case 'd':
calc.div(a, b, &result);
break;
case 'p':
calc.pow(a, b, &result);
break;
default:
fprintf(stderr, "Unknown command\n");
exit(0);
}
if (calc.error)
calc.soap_stream_fault(std::cerr);
else
printf("result = %g\n", result);
return 0;
}