/*
 *Sample Code for Array: By Krishna Kumar Rajagopalan
 *Uses a RPC Web Service
 *
 */

#include "ArrayTestPortType.hpp"
#include <stdio.h>
#include <iostream>
//#include <./../src/soap/SoapDeSerializer1.h> //points to SoapSerializer modified file SoapSerializer
//#include <arpa/inet.h>
//#include <netdb.h>
#define WSDL_DEFAULT_ENDPOINT "http://localhost:80/axis/Arraytest"

unsigned int ARRAY_SIZE=1;

static void
usage (char *programName, char *defaultURL)
{
    cout << "\nUsage:\n"
	<< programName << " [-? | service_url] " << endl
	<< "    -?             Show this help.\n"
	<< "    service_url    URL of the service.\n"
	<< "    Default service URL is assumed to be " << defaultURL << endl;
}


int main(int argc,char *argv[])
{
    char endpoint[256];
    sprintf (endpoint, "%s", WSDL_DEFAULT_ENDPOINT);

    int returnValue = 1;	// Assume Failure

       if (argc > 1)
    {
		// Watch for special case help request
		if (!strncmp (argv[1], "-", 1))	// Check for - only so that it works for
			//-?, -h or --help; -anything
		{
			usage (argv[0], endpoint);
			return 2;
		}
		sprintf (endpoint, argv[1]);
	}

	
	
	ArrayTestPortType ws (endpoint, APTHTTP1_1);
	intArrayType arr_in;
	arr_in.intItem.m_Size = 1;
	int arr[1];
	if( argc > 1 )
	arr[0]=atoi(argv[1]);
	else
	arr[0]=0;
	arr_in.intItem.m_Array = new int *;
	arr_in.intItem.m_Array[0] = &arr[0];
	   
	printf("\n Invoking Echo int Array ");
	
	try
	{
		ws.setTransportTimeout(200);
		ws.setTransportProperty("SOAPAction" , "Arraytest#echoIntArray");
		if (ws.echoIntArray(&arr_in)->intItem.m_Array == NULL )
		{
			printf("\n Received Null \n");
		}
		else	printf("\n Not null output ");
	}
	catch(AxisException& e)
	{
	         printf("Exception : %s\n", e.what());
	}
        catch(exception& e)
	{
	         printf("Unknown exception has occured\n");
	}
	catch(...)
	{
	         printf("Unknown exception has occured\n");
	}
	return 0;
}
