WebSphere Web Services Client for C++, Version 1.0.1 オペレーティング・システム: Linux, Windows

myGetQuote クライアント・アプリケーションのサンプル・コード

myGetQuote サンプルは、WebSphere Application Server 株価情報サンプルを基に作られています。

以下に示す myGetQuote サンプルは、WebSphere Application Server 株価情報サンプルを基につくられており、資料に以下の説明があります。「株価情報サンプルでは、株価情報クライアントの Simple Object Access Protocol (SOAP) から Java API for XML based RPC (JAX-RPC) へのマイグレーションを示します。WebSphere は、 JAX-RPC のクライアント・プログラミング・モデルでビルドする Web Services for J2EE (JSR 109) に対応しています。」

次のファイルは、<inst_dir>/samples/getQuote内にあります。

/*********************************************************************/
/* */
/* 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;
}

Reference topic

ご利用条件 | フィードバック (英語のみ)

Timestamp icon最終更新: 12 Jun 2006
(C) Copyright IBM Corporation 2005, 2006. All Rights Reserved.
このインフォメーション・センターでは Eclipse テクノロジーが採用されています。(http://www.eclipse.org)