⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 interop_test.cpp

📁 ESOAP一款专注于嵌入式的WEB SERVICE开发的软件。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/////////////////////////////////////////////////////////////////////////////
// $Id: interop_test.cpp,v 1.33 2001/09/11 11:45:52 rosimildo Exp $
//
// Copyright (c) 2001 Exor International Inc. All rights reserved.
//
// MODULE DESCRIPTION: 
// The "interop test suite" - client side for the eSoap toolkit C++.
//
// MODIFICATION/HISTORY:
//
// $Log: interop_test.cpp,v $
// Revision 1.33  2001/09/11 11:45:52  rosimildo
// changed copyright from Technopoint to Exit; updated version to 0.9
//
// Revision 1.32  2001/06/24 23:07:45  rosimildo
// More fixes to move to the 2001 schemas.
//
// Revision 1.31  2001/06/23 15:46:28  rosimildo
// Upagrade to 2001 XML Schema.
//
// Revision 1.30  2001/05/12 20:12:38  rosimildo
// Modifled new entry point for White Mesa.
//
// Revision 1.29  2001/05/09 20:59:34  rosimildo
// making sure that for Apache we use MS runtime
//
//
// Created 2001/02/08 Rosimildo da Silva, ConnectTel Inc.
// [rdasilva@connecttel.com]
//
/////////////////////////////////////////////////////////////////////////////

#include <math.h>
#include <float.h>
#include <stdio.h>
#include "soap_envelope.h"
#include "soap_transport.h"
#include "passivetimer.h"
#include "soap_namespace.h"
#include "soap_version.h"

/* must be the last include */
#ifdef MEMWATCH
#include <memwatch.h>
#endif

#define  INTEROP_TIMEOUT   10



const char *WHITE_MESA   = "White Mesa SOAP RPC 1.4";
const char *MS_NET_BETA2 = "MS .NET Beta 2 - RPC - typed";
const char *MS_NET_REMOTING_TYPED = "MS .NET Remoting -- 2001 typed.";
const char *MS_NET_REMOTING       = "MS .NET Remoting";


struct ToolKitInfo
{
   esoap::String maker;
   esoap::String endpoint;
   esoap::String soapaction;
   esoap::String name_space;
   esoap::String wsdl;
   esoap::String action_m_name_link;
   bool   useMethodName;

  ToolKitInfo( const char *mker, const char *end_p, const char *action, const char *ns, 
  			   const char *ws, const char *link ="", bool use= false )
  {
     maker    = mker;
     endpoint = end_p;
     soapaction = action;
     name_space =ns;
     wsdl = ws;
     action_m_name_link = link;
     useMethodName = use;
  }
};



esoap::Parameter *getRealParameter( 
                                    esoap::Envelope *in, 
                                    esoap::Parameter *ret,
                                    bool recursive = false )
{
 
  while( ret && ret->isHref() )
  {
    esoap::String href = ret->getHref();
    printf( "Got HREF=%s, name=%s\n" , href.c_str(), ret->getName().c_str() );
    ret  = in->getIdParameter( href );
    if( !recursive )
        break;
  }
  return ret;
}


/** append the method name to a SoapAction */
esoap::String getAction( const ToolKitInfo & tk, const char *method_name )
{
  esoap::String a = tk.soapaction;
  if( tk.useMethodName )
  {
    a += tk.action_m_name_link;
    a += esoap::NS::stripNS( method_name );
  }
  return a;
}

/** prints the information about the toolkits and the calls */
void printBegin( const char *func_name, const ToolKitInfo & tk, const char *value )
{
    printf( "CALL:       %s( %s ) --- TOOLKIT: %s\n" 
            "ENDPOINT:   %s\n"
            "SOAPAction: %s\n"
            "NANESPACE:  %s\n", 
            func_name, value, tk.maker.c_str(), tk.endpoint.c_str(), 
            getAction( tk, func_name ).c_str(), tk.name_space.c_str() );
}

/** print the fault information */
esoap::String printFault( const char *func_name, esoap::Fault *f )
{
   if( !f ) return "";
   printf( "%s FAULT: FaultCode: %s\nFaultString:%s    ==> FAILED\n",
          func_name, f->getCodeString().c_str(), f->getFaultString().c_str() );

   esoap::String rc = "FaultCode: ";
   rc +=  f->getCodeString();
   rc += "  FaultString: ";
   rc +=  f->getFaultString();
   return rc;
}


/** sends a string, and check if the same is received back */
bool echoString( const ToolKitInfo & tk, const esoap::String & value, 
                 esoap::String & error_status )
{
    static const char *method_name = "e:echoString";

    printBegin( method_name, tk, value.c_str() );
    esoap::Transport *ht = esoap::TransportFactory::create( tk.endpoint.c_str(),  
                                                          esoap::TransportFactory::HTTP );
    ht->setTimeout( INTEROP_TIMEOUT );
    esoap::Envelope    env;
    esoap::Method *m = env.setMethod( method_name, tk.name_space.c_str() );
    m->addString( "inputString", value.c_str() );
    bool rc = false;

    esoap::Envelope *in = ht->call( env, getAction( tk, method_name ).c_str() );
    if( in->success() )
    {
      esoap::Method    *resp = in->getMethod();
      esoap::Parameter *ret  = resp->getParameter( 0 );
      esoap::String    res   = ret->getString();
      if( res == value )
      {
        printf( "%s: %s  => %s   ===> PASSED \n" ,
                method_name, ret->getName().c_str(), res.c_str() );
        rc = true;
      }
      else
      {
        printf( "%s: %s  => %s   ===> FAILED \n" , 
                method_name, ret->getName().c_str(), res.c_str() );
        error_status = "OOPs -- wrong data";
      }
    }
    else
    {
      error_status = printFault( method_name, in->getFault() );
    }
    printf( "\n\n" );
    delete in;
    delete ht;
    return rc;
}


/** sends an integer, and check if the same is received back */
bool echoInteger( const ToolKitInfo & tk, const esoap::String & value,
                 esoap::String & error_status )
{
    static const char *method_name = "e:echoInteger";

    printBegin( method_name, tk, value.c_str() );
    esoap::Transport *ht = esoap::TransportFactory::create( tk.endpoint.c_str(),  
                                                          esoap::TransportFactory::HTTP );
    ht->setTimeout( INTEROP_TIMEOUT );
    esoap::Envelope    env;
    esoap::Method *m = env.setMethod( method_name, tk.name_space.c_str() );

    int val = atoi( value.c_str() );
    m->addInteger( "inputInteger", val );
    bool rc = false;
    esoap::Envelope *in = ht->call( env, getAction( tk, method_name ).c_str() );
    if( in->success() )
    {
      esoap::Method    *resp = in->getMethod();
      esoap::Parameter *ret  = resp->getParameter( 0 );
      int              res   = ret->getInteger();
      if( res == val )
      {
        printf( "%s: %s  => %d   ===> PASSED \n" ,
                method_name, ret->getName().c_str(), res );
        rc = true;
      }
      else
      {
        printf( "%s: %s  => %d   ===> FAILED \n" , 
                method_name, ret->getName().c_str(), res );
      }
    }
    else
    {
      error_status = printFault( method_name, in->getFault() );
    }
    printf( "\n\n" );
    delete in;
    delete ht;
    return rc;
}


/** sends a float, and check if the same is received back */
bool echoFloat( const ToolKitInfo & tk, const esoap::String & value,
                 esoap::String & error_status )
{
    static const char *method_name = "e:echoFloat";

    printBegin( method_name, tk, value.c_str() );
    esoap::Transport *ht = esoap::TransportFactory::create( tk.endpoint.c_str(),  
                                                          esoap::TransportFactory::HTTP );
    ht->setTimeout( INTEROP_TIMEOUT );
    esoap::Envelope    env;
    esoap::Method *m = env.setMethod( method_name, tk.name_space.c_str() );

    float val = atof( value.c_str() );
    m->addFloat( "inputFloat", val );
    bool rc = false;
    esoap::Envelope *in = ht->call( env, getAction( tk, method_name ).c_str() );
    if( in->success() )
    {
      esoap::Method    *resp = in->getMethod();
      esoap::Parameter *ret  = resp->getParameter( 0 );
      float            res   = ret->getFloat();
      if( fabs( res - val ) < 0.0001 )
//      if( res == val )
      {
        printf( "%s: %s  => %f   ===> PASSED \n" ,
                method_name, ret->getName().c_str(), res );
        rc = true;
      }
      else
      {
        printf( "%s: %s  => %f   ===> FAILED \n" , 
                method_name, ret->getName().c_str(), res );
      }
    }
    else
    {
      error_status = printFault( method_name, in->getFault() );
    }
    printf( "\n\n" );
    delete in;
    delete ht;
    return rc;
}


bool echoVoid( const ToolKitInfo & tk, const esoap::String & value,
                 esoap::String & error_status )
{
    static const char *method_name = "e:echoVoid";

    printBegin( method_name, tk, value.c_str() );
    esoap::Transport *ht = esoap::TransportFactory::create( tk.endpoint.c_str(),  
                                                          esoap::TransportFactory::HTTP );
    ht->setTimeout( INTEROP_TIMEOUT );
    esoap::Envelope    env;
    esoap::Method *m = env.setMethod( method_name, tk.name_space.c_str() );
    bool rc = false;
    esoap::Envelope *in = ht->call( env, getAction( tk, method_name ).c_str() );
    if( in->success() )
    {
      esoap::Method    *resp = in->getMethod();
      if( resp )
      {
         printf( "%s: %s  =>  ===> PASSED \n" ,
                  method_name, resp->getName().c_str() );
      }
      else
      {
         printf( "%s: %s  =>  ===> PASSED \n" ,
                  method_name, method_name );
      }
      rc = true;
    }
    else
    {
      error_status = printFault( method_name, in->getFault() );
    }
    printf( "\n\n" );
    delete in;
    delete ht;
    return rc;
}


bool echoStringArray( const ToolKitInfo & tk, const esoap::String & value,
                 esoap::String & error_status )
{
    static const char *method_name = "e:echoStringArray";

    printBegin( method_name, tk, value.c_str() );
    esoap::Transport *ht = esoap::TransportFactory::create( tk.endpoint.c_str(),  
                                                          esoap::TransportFactory::HTTP );
    ht->setTimeout( INTEROP_TIMEOUT );
    esoap::Envelope    env;
    esoap::Method *m = env.setMethod( method_name, tk.name_space.c_str() );

    esoap::Array *a = new esoap::Array( "inputStringArray" );
    a->addString( value.c_str() );
    a->setType( esoap::xsd_string );
    m->addParameter( a );
    bool rc = false;
    esoap::Envelope *in = ht->call( env, getAction( tk, method_name ).c_str() );
    if( in->success() )
    {
      esoap::Method    *resp = in->getMethod();
      // return is an array....
      esoap::Array     *ret  = (esoap::Array  *)resp->getParameter( 0 );
      if( ret && ret->isHref() )
      {
        esoap::String href    = ret->getHref();
        printf( "Got HREF=%s\n" , href.c_str() );
        ret  = ( esoap::Array *)in->getIdParameter( href );
       
      }
      if( ret && ( ret->getParameterCount() > 0 ) )
      {
        esoap::String    res = ret->getParameter( 0 )->getString();
        if( res == value )
        {
          printf( "%s: %s  => %s   ===> PASSED \n" ,
                  method_name, ret->getName().c_str(), res.c_str() );
          rc = true;
        }
        else
        {
           printf( "%s: %s  => %s   ===> FAILED \n" ,
                  method_name, ret->getName().c_str(), res.c_str() );
        }
      }
      else
      {
        printf( "%s: %s  =>  ===> FAILED \n" , 
                method_name, resp->getName().c_str() );
      }
    }
    else
    {
       error_status = printFault( method_name, in->getFault() );
    }
    printf( "\n\n" );
    delete in;
    delete ht;
    return rc;
}


bool echoIntegerArray( const ToolKitInfo & tk, const esoap::String & value,
                 esoap::String & error_status )
{
    static const char *method_name = "e:echoIntegerArray";

    printBegin( method_name, tk, value.c_str() );
    esoap::Transport *ht = esoap::TransportFactory::create( tk.endpoint.c_str(),  
                                                          esoap::TransportFactory::HTTP );
    ht->setTimeout( INTEROP_TIMEOUT );
    esoap::Envelope    env;
    esoap::Method *m = env.setMethod( method_name, tk.name_space.c_str() );

    esoap::Array *a = new esoap::Array( "inputIntegerArray" );
    int val = atoi( value.c_str() );
    a->addInteger( val );
    a->setType( esoap::xsd_int );
    m->addParameter( a );
    bool rc = false;
    esoap::Envelope *in = ht->call( env, getAction( tk, method_name ).c_str() );
    if( in->success() )
    {
      esoap::Method    *resp = in->getMethod();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -