WebSphere Message Service Clients: Web Services Client for C++, Version 1.1 作業系統: Linux, Windows

myGetQuote 用戶端應用程式的範例程式碼

myGetQuote 範例是源自 WebSphere Application Server「股票報價」範例。

下面的 myGetQuote 範例是源自 WebSphere Application Server「股票報價」範例, 在文件中將以下列方式來參考:「股票報價」範例說明將股票報價用戶端從「簡易物件存取通訊協定 (SOAP)」移轉至 XML 型 RPC 的 Java API (JAX-RPC)。WebSphere 支援 J2EE (JSR 109) 的 Web 服務,該服務是建置在 JAX-RPC 的用戶端程式設計模型之上。

您可以在 <inst_dir>/samples/getQuote 中找到下列檔案。

/*********************************************************************/
 /*                                                                   */
 /*                  IBM Web Services Client for C/C++                */
 /*                                                                   */
 /*  檔名:          myGetQuote.cpp                                   */
 /*                                                                   */
 /*  說明:          用來呼叫產生的                                   */
 /*                  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.                             */
 /*                                                                   */
 /*  狀態:1.0 版                                      */
 /*  <END_COPYRIGHT>                                                  */
 /*                                                                   */
 /*********************************************************************/

// 併入 WSDL2Ws 產生的 StockQuote.hpp
#include "StockQuote.hpp"

// 併入用來定義函數 cout 的 C++ 標頭檔
#include <iostream>

int main()
{
	try
	{
		// 建立一個字元字串,其中包含
		// GetQuoteService Web 服務的伺服器端點 URI。然後將端點傳送至
		// WSDL2Ws 工具所產生的 GetQuote 類別的實例產生器 (instantiator)。
		// 端點將指向 Websphere Application Server 上的服務位置。
		//
		char *  pszEndpoint = "http://<ServerName>:<PortNumber>/StockQuote/services/
urn:xmltoday-delayed-quotes";
		StockQuote * pwsStockQuote = new StockQuote( pszEndpoint);

// 如果您的網路需要使用 Proxy,請新增下列程式行
// 來配置 AxisClient。
		/*
char *  pszProxyURL = "<ProxyHost>";
int     iProxyPortNumber = <ProxyPort>;

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

		// 如果您使用處理常式,而 WSDL 並沒有識別 SOAP 動作,
		// 則您需要先新增 SOAP 動作,然後再呼叫 Web 服務。
		/*
		char *  pszHandlerName = "Handler";

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

		// 設定 Web 服務要報價的股票名稱。如果只要測試
		// Web 服務,則使用 XXX。這樣應該會傳回股票報價 55.25。
		char *  pszStockName = "XXX";

		// 呼叫屬於 StockQuote Web 服務的 'getQuote' 方法,
		// 來尋找 pszStockName 中指定給定公司名稱的股票報價。
		// 這個方法會將報價搜尋的結果當作
		// xsd__float 類型來傳回。
		xsd__float  fQuoteDollars = pwsStockQuote-> getQuote( pszStockName);

		// 輸出報價。如果不知道股票名稱,則 getQuote() 會
		// 傳回 -1。伺服器會辨識這個名稱,並且傳回
		// 常數值。

		if( fQuoteDollars != -1)
		{
			cout << "" << pszStockName << " 的股票報價是 $" << fQuoteDollars
 << endl;
		}
		else
		{
			cout << "" << pszStockName << 沒有股票報價 endl;
		}

		// 刪除 Web 服務。
		delete pwsStockQuote;
	}
	catch( SoapFaultException& sfe)
	{
		// 捕捉任何其他 SOAP 錯誤
		cout << "SoapFaultException: " << sfe.getFaultCode() << " " << sfe.what()
<< endl;
	}
	catch( AxisException& e)
	{
		// 捕捉 AXIS 異常狀況
	cout << "AxisException: " << e.getExceptionCode() << " " << e.what() << endl;
	}
	catch( exception& e)
	{
		// 捕捉一般異常狀況
	cout << "不明的異常狀況: " << e.what() << endl;
	}
	catch( ...)
	{
		// 捕捉任何其他異常狀況
	cout << "未指定的異常狀況: " << endl;
	}

    // 結束。
    		return 0;
}

Reference topic

使用條款 | 此頁的評等

「時間戳記」圖示前次更新: 28 Apr 2006
(C) Copyright IBM Corporation 2005. All Rights Reserved.
本資訊中心採用 Eclipse 技術。(http://www.eclipse.org)