OpenVMS Source-Code Demos

SIMPLE_SERVICE_CLIENT_100.C

#define VERSION	"simple_service_client_100.2"					// <<<--- change as required
//===============================================================================================================================
// title  : simple_service_client_xxx.c
// author : Neil Rieck
// created: 2011-10-14
// Build  :	@build_simple_service_step1_common.com (only need to do this once for every new WSDL)
//		@build_simple_service_step2_server.com
//		@build_simple_service_step3_client.com
// Notes  : Attention Hackers! be prepared to inspect file "GSOAP$ROOT:[000000.INCLUDE]stdsoap2.h"
//          looking at the SOAP structure to find variable names then working backwards
//===============================================================================================================================
// history:
// ver who when   what
// --- --- ------ ---------------------------------------------------------------------------------------------------------------
// 100 NSR 111014 1. initial work (new program)
//     NSR 111015 2. more work
//
//	remember to modify VERSION on the first line of this file
//===============================================================================================================================
#define PATH	"csmis$root3:[dvlp._gsoap_simple_service_2011]"			// our current development directory
#define NSR_DEBUG	0							// must link with gsoap$root:[lib]gsoapdbg.olb
#define NSR_STRICT	1							// XML must be well-formed and valid
#define	PRODUCTION	0							// 1=Apache Server, 0=Green Screen Server
#if (PRODUCTION == 1)								//
char server[] = "http://www.bellics.com/simple_service";			// served-up by Apache
#else										//
char server[] = "127.0.0.1:8123";						//
#endif										//
//
//	import the usual stuff
//
#include <stdio.h>								//
#include <stdlib.h>								//
#include <string.h>								//
#include <time.h>								//

//
//	stuff needed for our gSOAP app
//
#include "SIMPLE_SERVICE_GSC_H.H"						// generated by tool "soapcpp2"
#include "SIMPLESERVICESOAP11BINDING.NSMAP"					// generated by tool "soapcpp2"
//==============================================================================
//	main
//==============================================================================
int gDcl;                                                                       // global variable

void display_help(){
	fprintf(stderr, "Example Usage: cmd ADD 123 456\n");
	fprintf(stderr, "Example Usage: cmd SUBTRACT 123 456\n");
	fprintf(stderr, "Example Usage: cmd ECHO \"this is a test\"\n");
}

int main(int argc, char **argv)							//
{	int m, s;								// master and slave sockets
	char choice;								//
	int reqd_params;							//
	struct soap soap;							//
	//
	//	note: this command-line option stuff will only be used for developing skelton code.
	//	For production mode it might make more sense to build three stand-alone clients.
	//
	fprintf(stderr,"Program: %s\n",VERSION);
	if (argc < 2){
	    display_help();
	    exit(0);
	}
	choice = *argv[1];
	switch (choice) {
	    case 'a':
	    case 'A':
		choice = 'a';
		reqd_params = 3+1;
		break;
	    case 's':
	    case 'S':
		choice = 's';
		reqd_params = 3+1;
		break;
	    case 'e':
	    case 'E':
		choice = 'e';
		reqd_params = 2+1;
		break;
	    default:
		fprintf(stderr, "Unsupported operation\n");
		display_help();
		exit(0);
	}
	if (argc != reqd_params) {
		fprintf(stderr, "Expected %d command line params but received %d\n",reqd_params, argc);
		display_help();
		exit(0);
	}
	soap_init(&soap);							// magic
#if (NSR_DEBUG==1)
	char logf1[255];
	char logf2[255];
	char logf3[255];
	sprintf(logf1,"%s%s",PATH,"aaa_c_recv.log");				// for extensive client logging
	sprintf(logf2,"%s%s",PATH,"aaa_c_sent.log");				//
	sprintf(logf3,"%s%s",PATH,"aaa_c_test.log");				//
	soap_set_recv_logfile(&soap, logf1);					//
	soap_set_sent_logfile(&soap, logf2);					//
	soap_set_test_logfile(&soap, logf3);					//
#endif
#ifdef NSR_STRICT
	printf("-i- set strict\n");						//
	soap_set_imode(&soap, SOAP_XML_STRICT);					// set input mode strict
#endif
	printf("-i- server: %s\n",server);
//------------------------------------------------------------------------------
//	"ssAdd"
//
//	1. the following declaration was found in file: SOAPCLIENT.C
//	2. it can also be found in file "SOAPSTUB.H" near "Client-Side Call Stubs"
//
//	soap_call___ns2__ssAdd(	struct soap			*soap,
//				const char			*soap_endpoint,
//				const char			*soap_action,
//				struct _ns1__ssAdd		*ns1__ssAdd,
//				struct _ns1__ssAddResponse	*ns1__ssAddResponse)
//------------------------------------------------------------------------------
//trek1
    if (choice == 'a') {
	printf("firing: ssAdd\n");						//
	struct _ns1__ssAdd		myAddRequest;				//
	struct _ns1__ssAddResponse	myAddResponse;				//
	int param0, param1;
	param0 = strtod(argv[2], NULL);
	param1 = strtod(argv[3], NULL);
	myAddRequest.param0	= &param0;					//
	myAddRequest.param1	= &param1;					//
	soap_call___ns2__ssAdd(&soap, server, "", &myAddRequest, &myAddResponse);
	if (soap.error)								//
	{ soap_print_fault(&soap, stderr);					//
	    printf("oops\n");							//
	    exit(1);								//
	}else{
	    printf("cool\n");
	    printf("response: %d\n",*myAddResponse.return_);
	}
	soap_destroy(&soap);
	soap_end(&soap);
	soap_done(&soap);
	printf("exiting\n");
	return 1;								// vms-ok
    }

//------------------------------------------------------------------------------
//	"ssSubtract"
//
//	1. the following declaration was found in file: SOAPCLIENT.C
//	2. it can also be found in file "SOAPSTUB.H" near "Client-Side Call Stubs"
//
//	soap_call___ns2__ssSubtract(	struct soap			*soap,
//					const char			*soap_endpoint,
//					const char			*soap_action,
//					struct _ns1__ssSubtract		*ns1__ssSubtract,
//					struct _ns1__ssSubtractResponse	*ns1__ssSubtractResponse)
//------------------------------------------------------------------------------
//trek2
    if (choice == 's') {
	printf("firing: ssSubtract\n");						//
	struct _ns1__ssSubtract		mySubtractRequest;			//
	struct _ns1__ssSubtractResponse	mySubtractResponse;			//
	int param3, param4;
	param3 = strtod(argv[2], NULL);
	param4 = strtod(argv[3], NULL);
	mySubtractRequest.param0	= &param3;				//
	mySubtractRequest.param1	= &param4;				//
	soap_call___ns2__ssSubtract(&soap, server, "", &mySubtractRequest, &mySubtractResponse);
	if (soap.error)								//
	{ soap_print_fault(&soap, stderr);					//
	    printf("oops\n");							//
	    exit(1);								//
	}else{
	    printf("cool\n");
	    printf("response: %d\n",*mySubtractResponse.return_);
	}
	soap_destroy(&soap);
	soap_end(&soap);
	soap_done(&soap);
	printf("exiting\n");
	return 1;								// vms-ok
    }
//------------------------------------------------------------------------------
//	"ssEcho"
//
//	1. the following declaration was found in file: SOAPCLIENT.C
//	2. it can also be found in file "SOAPSTUB.H" near "Client-Side Call Stubs"
//
//	soap_call___ns2__ssEcho(	struct soap			*soap,
//					const char			*soap_endpoint,
//					const char			*soap_action,
//					struct _ns1__ssEcho		*ns1__ssEcho,
///					struct _ns1__ssEchoResponse	*ns1__ssEchoResponse)
//------------------------------------------------------------------------------
//trek3
    if (choice == 'e') {
	printf("firing: ssEcho\n");						//
	struct _ns1__ssEcho		myEchoRequest;				//
	struct _ns1__ssEchoResponse	myEchoResponse;				//
	myEchoRequest.param0	= argv[2];					//
	soap_call___ns2__ssEcho(&soap, server, "", &myEchoRequest, &myEchoResponse);
	if (soap.error)								//
	{ soap_print_fault(&soap, stderr);					//
	    printf("oops\n");							//
	    exit(1);								//
	}else{
	    printf("cool\n");
	    printf("result: %s\n",myEchoResponse.return_);
	}
	soap_destroy(&soap);
	soap_end(&soap);
	soap_done(&soap);
	printf("exiting\n");
	return 1;								// vms-ok
    }

//
//	catch-all
//
	printf("Oops, nothing fired\n");					//
	soap_destroy(&soap);
	soap_end(&soap);
	soap_done(&soap);
	printf("exiting\n");
	return 2;								// vms-error
}