WebSphere Web Services Client for C++, Version 1.0.1 운영 체제: Linux, Windows

샘플 클라이언트 핸들러 코드

이러한 코드 샘플은 클라이언트 응용프로그램에 대한 핸들러를 작성하는 방법에 대해 설명하는 템플리트를 제공합니다.

다음은 주식 시세 샘플에 대한 예제 파일입니다. 3개의 샘플 파일이 있습니다.

이러한 파일은 <inst_dir>/samples/handlers에 있습니다.

myClientHandler.hpp

 /*********************************************************************/
 /*                                                                   */
 /*                  IBM Web Services Client for C/C++                */
 /*                                                                   */
 /*  FILE NAME:      myClientHandler.hpp                              */
 /*                                                                   */
 /*  DESCRIPTION:    Example Client handler header file               */
 /*                  for the Stock Quote sample                       */
 /*                                                                   */
 /*********************************************************************/
 /*  <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>                                                  */
 /*                                                                   */
 /*********************************************************************/

#if !defined( _HANDLER_HPP__INCLUDED_)
#define _HANDLER_HPP__INCLUDED_

#include <axis/Handler.hpp>

AXIS_CPP_NAMESPACE_USE

class myClientHandler : public Handler
{
 public:
    myClientHandler();
    virtual ~myClientHandler();

    // init is called when the Handler is loaded.
    int  AXISCALL   init();

    // invoke is called when AxisClient is about to send the request SOAP message
    // or when a response message has just been received.
    int  AXISCALL   invoke( void * pvIMsg);

    // onFault is called if there is a fault with message processing.
    void AXISCALL   onFault( void * pvIMsg);

    // fini is called when the Handler is about to unloaded.
    int  AXISCALL   fini();
};

#endif // !defined(_HANDLER_HPP__INCLUDED_)

myClientHandler.cpp

/*********************************************************************/
 /*                                                                   */
 /*                  IBM Web Services Client for C/C++                */
 /*                                                                   */
 /*  FILE NAME:      myClientHandler.cpp                              */
 /*                                                                   */
 /*  DESCRIPTION:    Example Client Handler                           */
 /*                  for the stock quote sample                       */
 /*                                                                   */
 /*********************************************************************/
 /*  <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 myClientHandler header file to obtain the class definition, etc.
#include "myClientHandler.hpp"

// Include the header file to obtain the BasicHandler object, etc.
#include <axis/GDefine.hpp>
#include <axis/IHandlerSoapSerializer.hpp>
#include <axis/IHandlerSoapDeSerializer.hpp>
#include <iostream>

// myHandler is called when the object is created.
myClientHandler::myClientHandler()
{
}

// ~myClientHandler is called when the object is destroyed.
myClientHandler::~myClientHandler()
{
}

int myClientHandler::invoke( void * pvHandlerMessage)
{
    // Cast the current message into the IMessageData type.  This will allow the
    // user to change the SOAP message as appropriate.
    IMessageData * pIMsgData = (IMessageData *) pvHandlerMessage;

    // Check if the SOAP message is just about to be transmitted or has just been
    // received.
    if( pIMsgData->isPastPivot())
    {
        // Yes - the available SOAP message is a response
        cout << "Past the pivot point – Handler can see the response message." 
<< endl;
    }
    else
    {
        // No - the available SOAP message is a request
        cout << "Before the pivot point – Handler can see the request message\n" 
<< endl;
    }

    return AXIS_SUCCESS;
}

void myClientHandler::onFault( void * pvFaultMessage)
{
    // Please leave empty.
}

int myClientHandler::init()
{
    return AXIS_SUCCESS;
}

int myClientHandler::fini()
{
    return AXIS_SUCCESS;
}

myClientHandlerFactory.cpp

 /*********************************************************************/
 /*                                                                   */
 /*                  IBM Web Services Client for C/C++                */
 /*                                                                   */
 /*  FILE NAME:      myClientHandlerFactory.cpp                       */
 /*                                                                   */
 /*  DESCRIPTION:    Example client handler factory                   */
 /*                  for the stock quote sample                       */
 /*                                                                   */
 /*********************************************************************/
 /*  <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 myClientHandler header file to obtain the class definition, etc.
#include "myClientHandler.hpp"

// Include the header file to obtain the BasicHandler object, etc.
#include <axis/GDefine.hpp>

// External methods available to the loader of this handler library.
extern "C"
{
 // GetClassInstance is passed a pointer to a pointer that will contain the
 // handler object to be created by this factory.  Before the handler object is
 // returned, it is wrapped in a BasicHandler object and the handler's
 // initialise method is called.
 STORAGE_CLASS_INFO int GetClassInstance( BasicHandler ** ppClassInstance)
 {
     *ppClassInstance = new BasicHandler();

      myClientHandler * pmyClientHandler = new myClientHandler();

      // Setting functions to zero indicates that the handler is a C++ type
      (*ppClassInstance)->_functions = 0;

      // If the handler was loaded successfully, save the handler object and
      // initialise it.
      if( pmyClientHandler)
      {
          (*ppClassInstance)->_object = pmyClientHandler;

          return pmyClientHandler->init();
      }

      // If the hander was not loaded successfully, then return an error.        
      return AXIS_FAIL;
 }

 // DestroyInstance is passed a pointer to a generic BasicHandler object that
 // contains an instance of this type of handler object.  The handler is
 // unwrapped from the BasicHandler object whereupon, the handler's finish
 // method is called before deleting the handler and then the BasicHandler
 // wrapper.
 STORAGE_CLASS_INFO int DestroyInstance( BasicHandler * pClassInstance)
 {
     if( pClassInstance)
     {
         //Cast the generic handler object to the specific class.
         myClientHandler * pmyClientHandler = static_cast<myClientHandler*> 
(pClassInstance->_object);

         // Call the finish method on the handler.  This will allow the handler to
         // ‘tidy’ before it is deleted.
         pmyClientHandler->fini();

         // Delete the handler objects.
         delete pmyClientHandler;
         delete pClassInstance;

         // Return success.
         return AXIS_SUCCESS;
     }

     // Return error if there was no handler to close down and delete.
     return AXIS_FAIL;
 }
}

Reference topic

이용약관 | 피드백

시간소인 아이콘마지막 갱신 날짜: 3 Mar 2006
http://publib.boulder.ibm.com/infocenter/dmndhelp/v6rxmx/index.jsp?topic=/com.ibm.websphere.wscc.doc.nl1\ref\wscc_rclihandsample.html

(C) Copyright IBM Corporation 2005. All Rights Reserved.
이 information Center는 Eclipse 기술을 기반으로 합니다. (http://www.eclipse.org)