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

📄 esoapclient.cpp

📁 ESOAP一款专注于嵌入式的WEB SERVICE开发的软件。
💻 CPP
字号:
/////////////////////////////////////////////////////////////////////////////
// $Id: esoapclient.cpp,v 1.31 2001/09/11 11:45:52 rosimildo Exp $
//
// Copyright (c) 2001 Exor International Inc. All rights reserved.
//
// MODULE DESCRIPTION: 
// A simple test example to show the usage of the embbeded SOAP toolkit.
//
// MODIFICATION/HISTORY:
//
// $Log: esoapclient.cpp,v $
// Revision 1.31  2001/09/11 11:45:52  rosimildo
// changed copyright from Technopoint to Exit; updated version to 0.9
//
// Revision 1.30  2001/09/01 14:33:22  rosimildo
// Fixed client access from eCos.
//
// Revision 1.29  2001/07/28 14:02:20  rosimildo
// Added basic auth framework.
//
// Revision 1.28  2001/05/09 18:18:06  rosimildo
// making sure that for Apache we use MS runtime
//
//
// Created 2001/02/08 Rosimildo da Silva, ConnectTel Inc.
// [rdasilva@connecttel.com]
//
/////////////////////////////////////////////////////////////////////////////

#include <stdio.h>
#include "soap_envelope.h"
#include "soap_transport.h"
#include "passivetimer.h"
#ifdef __ECOS
#include <network.h>
#endif
/* must be the last include */
#ifdef MEMWATCH
#include <memwatch.h>
#endif

#ifdef __ECOS
#define ESOAP_SERVER_URL    "http://192.168.0.5:8080/rpcrouter"
#else
#define ESOAP_SERVER_URL    "http://localhost:8080/rpcrouter"
#endif

int main(int argc, char **argv)
{
  int loops = 1;
  const char *url  =  ESOAP_SERVER_URL;
  bool mem_chk = false;

#ifndef __ECOS
  if( argc == 2 )
  {
    loops = atoi( argv[1] );
  }
  else if( argc == 3 )
  {
    loops = atoi( argv[1] );
    url  =  argv[ 2 ];
  }
  else if( argc == 4 )
  {
    loops = atoi( argv[1] );
    url  =  argv[ 2 ];
	 mem_chk = true;
  }
#else

    loops = 500;
    init_all_network_interfaces();
    if( !eth0_up ) 
    {
	   assert( 0 );
	}
#endif

  printf( "URL= %s,  loops=%d\n", url, loops );
  esoap::Envelope    env;
#if TEST_ADD_ARRAY
  esoap::Method *m = env.setMethod( "addArray" );
  esoap::Array *a = new esoap::Array;
  a->setType( esoap::xsd_int );
  a->addInteger( 100 );
  a->addInteger( 50 );
  a->addInteger( 10 );
  a->addInteger( 5 );
  m->addParameter( a ); 

#else
  esoap::Method *m = env.setMethod( "add" );
  m->addInteger( "a", 100 );
  m->addInteger( "b", 20 );

/*
  esoap::Header *h = env.setHeader();
  h->addString( "m:trx", "need understand this" );
  h->setMustUnderstand( true );
*/

  esoap::Parameter *s1 = new esoap::Parameter( "myId", "ID1" );
  s1->setId( "bar" );
  m->addParameter( s1 ); 

  esoap::Parameter *s2 = new esoap::Parameter( "myHref" );
  s2->setHref( "bar" );
  m->addParameter( s2 ); 
 
#endif

  // if you want to see wire data.....
  // esoap::String s;
  // s = "";
  // env.serialize( s );
  // printf( "%s\n", s.c_str() );

  esoap::Transport *ht = esoap::TransportFactory::create( url,
                                                          esoap::TransportFactory::HTTP );
//  ht->setBasicAuthentication( "joe", "esoap" );
  PassiveTimer pt( 0 );
  int ntimes = loops;
  pt.reset();
  while( loops-- )
  {
    esoap::Envelope *in = ht->call( env, "some:action" );
    if( in->success() )
    {
      esoap::Method    *resp = in->getMethod();
      esoap::Parameter *sum  = resp->getParameter( 0 );
      printf( "Sucess: SUM is: %d\n", sum->getInteger() );
    }
    else
    {
      if( in->isFault() )
      {
         esoap::Fault *f = in->getFault();
         printf( "Fault Received: Faultcode: %s\nFaultstring:%s\n",
                  f->getCodeString().c_str(), f->getFaultString().c_str() );
      }
    }
    // to see what we received....
    // in->serialize( s );
    // printf( "%s\n", s.c_str() );
    delete in;
  }
  printf( "Elapsed time per call ==> %d milliseconds\n", pt.elapsed()/ntimes );
  
  if( mem_chk )
  {
      env.clear();
      env.setMethod( "memoryCheck" );
      esoap::Envelope *in = ht->call( env );
      delete in;
  }

  delete ht;
  // just to cleanup the memory...
  delete esoap::ParameterFactory::setInstance( 0 );
  return 0;
}

⌨️ 快捷键说明

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