WebSphere Business Integration Web Services Client for C++, Version 1.1 Operating Systems: AIX, Linux, Windows

Sample code for myGetQuote client application

The myGetQuote sample originates from the WebSphere Application Server Stock Quote sample.

The myGetQuote sample shown below originates from the WebSphere Application Server Stock Quote sample and is referenced in the documentation as follows: “The Stock Quote sample illustrates migration of a stock quote client from Simple Object Access Protocol (SOAP) to Java API for XML based RPC (JAX-RPC). WebSphere supports Web Services for J2EE (JSR 109) which builds on a client programming model on JAX-RPC”.

There is a C++ version and a C version of the sample code for the myGetQuote client application. Both files can be found in <inst_dir>/samples/getQuote.

The following C++ source file listing is for myGetQuote.cpp

/*********************************************************************/
 /*                                                                   */
 /*                  IBM Web Services Client for C/C++                */
 /*                                                                   */
 /*  FILE NAME:      myGetQuote.cpp                                   */
 /*                                                                   */
 /*  DESCRIPTION:    main program to call the generated               */
 /*                  StockQuote stub                                  */
 /*                                                                   */
 /*********************************************************************/
 /*  <START_COPYRIGHT>                                                */
 /*                                                                   */
 /*  Licensed Materials - Property of IBM                             */
 /*                                                                   */
 /*  6205-001                                                         */
 /*                                                                   */
 /*  (c) Copyright IBM Corp. 2004, 2005                               */
 /*  All Rights Reserved                                              */
 /*                                                                   */
 /*  U.S. Government Users Restricted Rights - use,                   */
 /*  duplication or disclosure restricted by GSA                      */
 /*  ADP Schedule Contract with IBM Corp.                             */
 /*                                                                   */
 /*  Status: Version 1 Release 0                                      */
 /*  <END_COPYRIGHT>                                                  */
 /*                                                                   */
 /*********************************************************************/

// Include the WSDL2Ws generated StockQuote.hpp 
#include "StockQuote.hpp"

// Include the C++ header file that defines the function cout
#include <iostream>

int main()
{
	try
	{
		// Create a character string that contains the server endpoint URI for the
		// GetQuoteService web service.  Then pass the endpoint to the instantiator
		// for the GetQuote class that was generated by the WSDL2Ws tool.  The
		// endpoint will pointing to the location of service on Websphere Application
		// Server.
		char *  pszEndpoint = "http://<ServerName>:<PortNumber>/StockQuote/services/urn:xmltoday-delayed-quotes";
		StockQuote * pwsStockQuote = new StockQuote( pszEndpoint);

		// If your network requires the use of a proxy, then add the following line of
		// code to configure AxisClient.
		/*
		char *  pszProxyURL = "<ProxyHost>";
		int     iProxyPortNumber = <ProxyPort>;

		pwsStockQuote->setProxy( pszProxyURL, iProxyPortNumber);
		*/

		// If you are using handlers, if the WSDL does not identify the SOAP action
		// then you will need to add your SOAP action before calling the web service.
		/*
		char *  pszHandlerName = "Handler";

		pwsStockQuote->setTransportProperty( SOAPACTIONHEADER , pszHandlerName);
		*/

		// Set the stock name to be quoted by the web service.  To test just the
		// web service, XXX is being used. This should return a stock quote of 55.25.  
		char *  pszStockName = "XXX";

		// Call the 'getQuote' method that is part of the StockQuote web service to
		// find the quoted stock price for the given company whose name is in
		// pszStockName.  The result of the quote search will be returned by this
		// method as a xsd__float type.
		xsd__float  fQuoteDollars = pwsStockQuote-> getQuote( pszStockName);

		// Output the quote.  If the stock name is unknown, then getQuote() will
		// return -1.  This name was recognized by the server and a constant value
		// is returned.

		if( fQuoteDollars != -1)
		{
			cout << "The stock quote for " << pszStockName << " is $" << fQuoteDollars << endl;
		}
		else
		{
			cout << "There is no stock quote for " << pszStockName << endl;
		}

		// Delete the web service.
		delete pwsStockQuote;
	}
	catch( SoapFaultException& sfe)
	{
		// Catch any other SOAP faults
		cout << "SoapFaultException: " << sfe.getFaultCode() << " " << sfe.what() << endl;
	}
	catch( AxisException& e)
	{
		// Catch an AXIS exception
	cout << "AxisException: " << e.getExceptionCode() << " " << e.what() << endl;
	}
	catch( exception& e)
	{
		// Catch a general exception
	cout << "Unknown Exception: " << e.what() << endl;
	}
	catch( ...)
	{
		// Catch any other exception
	cout << "Unspecified Exception: " << endl;
	}

    // Exit.
    return 0;
}

The following C source file listing is for myGetQuote.c

/*********************************************************************/
/*                                                                   */
/*                  IBM Web Services Client for C/C++                */
/*                                                                   */
/*  FILE NAME:      myGetQuote.c                                     */
/*                                                                   */
/*  DESCRIPTION:    main program to call the generated               */
/*                  StockQuote stub                                  */
/*                                                                   */
/*********************************************************************/
/* LICENSE AND DISCLAIMER                                            */
/* ----------------------                                            */
/* This material contains IBM copyrighted sample programming source  */
/* code ( Sample Code ).                                             */
/* IBM grants you a nonexclusive license to compile, link, execute,  */
/* display, reproduce, distribute and prepare derivative works of    */
/* this Sample Code.  The Sample Code has not been thoroughly        */
/* tested under all conditions.  IBM, therefore, does not guarantee  */
/* or imply its reliability, serviceability, or function. IBM        */
/* provides no program services for the Sample Code.                 */
/*                                                                   */
/* All Sample Code contained herein is provided to you "AS IS"       */
/* without any warranties of any kind. THE IMPLIED WARRANTIES OF     */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND             */
/* NON-INFRINGMENT ARE EXPRESSLY DISCLAIMED.                         */
/* SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED          */
/* WARRANTIES, SO THE ABOVE EXCLUSIONS MAY NOT APPLY TO YOU.  IN NO  */
/* EVENT WILL IBM BE LIABLE TO ANY PARTY FOR ANY DIRECT, INDIRECT,   */
/* SPECIAL OR OTHER CONSEQUENTIAL DAMAGES FOR ANY USE OF THE SAMPLE  */
/* CODE INCLUDING, WITHOUT LIMITATION, ANY LOST PROFITS, BUSINESS    */
/* INTERRUPTION, LOSS OF PROGRAMS OR OTHER DATA ON YOUR INFORMATION  */
/* HANDLING SYSTEM OR OTHERWISE, EVEN IF WE ARE EXPRESSLY ADVISED OF */
/* THE POSSIBILITY OF SUCH DAMAGES.                                  */
/*                                                                   */
/*  <START COPYRIGHT>                                                */
/*                                                                   */
/*  Licensed Materials - Property of IBM                             */
/*                                                                   */
/*  5724-M08                                                         */
/*                                                                   */
/*  (c) Copyright IBM Corp. 2006, 2006                               */
/*  All Rights Reserved                                              */
/*                                                                   */
/*  U.S. Government Users Restricted Rights - use,                   */
/*  duplication or disclosure restricted by GSA                      */
/*  ADP Schedule Contract with IBM Corp.                             */
/*                                                                   */
/*  Status: Version 1 Release 0                                      */
/*  <END COPYRIGHT>                                                  */
/*                                                                   */
/*********************************************************************/

#include <stdio.h>

#include <axis/ISoapFault.h>

// Include the WSDL2Ws generated StockQuote.h 
#include "StockQuote.h"

// Following function is used as stub exception handler
int globalExceptionOccurred = 0;
void StockQuoteExceptionHandler(int errorCode, char * errorString, 
                                AXISCHANDLE soapFault, void *faultdetail)
{
    if (NULL != soapFault)
        printf("SoapFaultException: %d %s\n", 
               axiscSoapFaultGetFaultcode(soapFault), 
               axiscSoapFaultGetFaultstring(soapFault));
    else
        printf("AxisException: %d %s\n", errorCode, errorString);

    globalExceptionOccurred = 1;
}


int main()
{
    char *  pszStockName;
    xsdc__float  fQuoteDollars;

    // Create a character string that contains the server endpoint URI for the
    // GetQuoteService web service.  Then pass the endpoint to the instantiator
    // for the GetQuote class that was generated by the WSDL2Ws tool.  The
    // endpoint will pointing to the location of service on Websphere Application
    // Server.
    char *  pszEndpoint = "http://<ServerName>:<PortNumber>/StockQuote/services/urn:xmltoday-delayed-quotes";

    AXISCHANDLE pwsStockQuote = get_StockQuote_stub( pszEndpoint);

    if (NULL == pwsStockQuote)
        return -1;

    // Set the stub exception handler function
    set_StockQuote_ExceptionHandler( pwsStockQuote, StockQuoteExceptionHandler );

    // If your network requires the use of a proxy, then add the following line of
    // code to configure AxisClient.
    /*
    axiscStubSetProxy(pwsStockQuote, "<ProxyHost>", <ProxyPort>);
    */


    // Set the stock name to be quoted by the web service.  To test just the
    // web service, XXX is being used. This should return a stock quote of 55.25.  
    pszStockName = "XXX";

    // Call the 'getQuote' method that is part of the StockQuote web service to
    // find the quoted stock price for the given company whose name is in
    // pszStockName.  The result of the quote search will be returned by this
    // method as a xsd__float type.
    fQuoteDollars = getQuote(pwsStockQuote, pszStockName);

    // Output the quote.  If the stock name is unknown, then getQuote() will
    // return -1.  If name was recognized by the server a value is returned.

    if (!globalExceptionOccurred)
    {
        if ( fQuoteDollars != -1)
            printf("The stock quote for %s is $%f\n", pszStockName, fQuoteDollars);
        else
            printf("There is no stock quote for %s\n", pszStockName);
    }

    // Delete the web service.
    destroy_StockQuote_stub(pwsStockQuote);

    // Exit.
    return 0;
}

Reference topic

Terms of Use | Rate this page

Last updated: 27 Sep 2006

© Copyright IBM Corporation 2005, 2006. All Rights Reserved.