📄 get_temp.cpp
字号:
/////////////////////////////////////////////////////////////////////////////
// $Id: get_temp.cpp,v 1.11 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: get_temp.cpp,v $
// Revision 1.11 2001/09/11 11:45:52 rosimildo
// changed copyright from Technopoint to Exit; updated version to 0.9
//
// Revision 1.10 2001/04/20 01:16:34 rosimildo
// Fixed to add namespace to methods.
//
// Revision 1.9 2001/03/11 15:40:29 rosimildo
// Updated License to all files.
//
//
// Created 2001/02/08 Rosimildo da Silva, ConnectTel Inc.
// [rdasilva@connecttel.com]
//
/////////////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include "soap_envelope.h"
#include "soap_transport.h"
/* must be the last include */
#ifdef MEMWATCH
#include <memwatch.h>
#endif
void help()
{
printf( "get temperarure from anywhere in US using ZipCode.\n" );
printf( "See XMethods.org for details: www.xmethods.org\n" );
printf( "Usage: get_temp <zipcode>\n" );
}
//
// uses the XMethods service to get the
// current temperature in a given U.S. zipcode region
// This is sample interface web services from XMethods.
// The services are listed and described on:
//
// http://www.xmethods.com/
//
//GetTemp: Weather Service
// =======================
// Service description URL: http://www.xmethods.com/detail.html?id=8
//
// Usage: get_temp <zipcode>
//
//
int main(int argc, char *argv[])
{
if( argc < 2 )
{
help();
exit( 2 );
}
esoap::String zipcode = argv[ 1 ];
// create envelope to hold out package....
esoap::Envelope env;
esoap::Method *m = env.setMethod( "ns1:getTemp", "urn:xmethods-Temperature" );
// set parameters for the call...
m->addString( "zipcode", zipcode.c_str() );
// create the transport protocol...
esoap::Transport *ht = esoap::TransportFactory::create(
"http://services.xmethods.net/soap/servlet/rpcrouter",
esoap::TransportFactory::HTTP );
// let's make the call riht here....
esoap::Envelope *in = ht->call( env );
// check whether we have a response ok or a fault...
if( in->success() )
{
esoap::Method *resp = in->getMethod();
esoap::Parameter *res = resp->getParameter( "return" );
if( res )
{
printf( "Temperature for ZipCode: %s is: %.1f degrees Fahrenheit.\n",
zipcode.c_str(), res->getFloat() );
}
else
{
printf( "ERROR: no such paramter\n" );
}
}
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() );
}
}
delete in;
delete ht;
// just to cleanup the memory...
delete esoap::ParameterFactory::setInstance( 0 );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -