国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

利用PocketSOAP鏈接webservice(2)---VC++

2024-07-21 02:21:44
字體:
來源:轉載
供稿:網友
pstemp.cpp
_______________________
// pstemp.cpp : defines the entry point for the console application.
//

#include "stdafx.h"
#include "resource.h"


int _tmain(int argc, lpctstr argv[])
{
    uses_conversion ;

    std::cout << "pocketsoap temperature demo" << std::endl ;

    // test useage from the mta, swap these over to test usage from a sta
    // coinitializeex(0,  coinit_apartmentthreaded ) ;
    coinitializeex(0,  coinit_multithreaded ) ;
    {
        // the zip code to find the temperature for
        ccombstr zip (l"94107") ;
        if ( argc > 1 )
            zip = argv[1] ;

        // create the envelope object
        ccomptr<isoapenvelope> e ;
        hresult hr = e.cocreateinstance(__uuidof(coenvelope)) ;
        if ( failed(hr))
        {
            std::cout << "failed to create envelope object, hr=" << std::hex << hr << std::endl ;
            return -1;
        }

        // set the methodname and namespace uri
        e->setmethod ( ccombstr("gettemp"), ccombstr("urn:xmethods-temperature") ) ;

        // get the parameters collection
        ccomptr<isoapnodes> p ;
        e->get_parameters(&p) ;

        // create a new parameter
        p->create ( ccombstr(l"zipcode"), ccomvariant(zip), null, null, null, null ) ;
        p.release() ;

        // create the transport object
        ccomptr<ihttptransport> t ;
        hr = t.cocreateinstance(__uuidof(httptransport)) ;
        if (failed(hr))
        {
            std::cout << "failed to create http object, hr=" << std::hex << hr << std::endl ;
            return -1 ;
        }
        // set the soapaction header
        t->put_soapaction(ccombstr(l"")) ;

        // serialize the envelope
        ccombstr env ;
        hr = e->serialize(&env) ;
        if (failed(hr))
        {
            std::cout << "failed to serialize envelope, hr=" << std::hex << hr << std::endl;
            return -1 ;
        }

        // send to the server
        // add a call to t->setproxy ( ccombstr(l"myproxy"), 8080 ) here if you
        // need to connect through a proxy server
        hr = t->send ( ccombstr(l"http://services.xmethods.net:80/soap/servlet/rpcrouter"), env ) ;
        if (failed(hr))
        {
            std::cout << "failed to send request, hr=" << std::hex << hr << std::endl;
            return -1 ;
        }

        // parse the response
        hr = e->parse ( ccomvariant(t), ccombstr(l"") ) ;
        if (failed(hr))
        {
            // extract the detailed error info if there is some
            ccomptr<ierrorinfo> e ;
            geterrorinfo(0, &e) ;
            if ( e )
            {
                ccombstr src, desc ;
                e->getsource(&src) ;
                e->getdescription(&desc) ;
                std::cout << "error in response, got error " << ole2a(desc) << " from " << ole2a(src) << ", [hr=" << std::hex << hr << "]" << std::endl;
            }
            else
                std::cout << "failed to parse response, [hr=" << std::hex << hr << "]" << std::endl;

            return -1 ;
        }

        // get the parameters collection again, to get the response parameters
        e->get_parameters(&p) ;
        ccomptr<isoapnode> retnode ;

        // get the first node in the parameters collection
        p->get_item(0, &retnode) ;

        // get the nodes value
        ccomvariant v ;
        retnode->get_value(&v) ;

        // change its type to a string
        v.changetype(vt_bstr) ;

        // print the results !
        std::cout << "cuurent temperature for zipcode " << ole2a(zip) << " is " << ole2a(v.bstrval) << std::endl ;
    }

    couninitialize();
    return 0;
}
stdafx.cpp
______________________________________
#include "stdafx.h"
#include <atlimpl.cpp>
stdafx.h
______________________________________
// stdafx.h : include file for standard system include files,
//  or project specific include files that are used frequently, but
//      are changed infrequently
//

#if !defined(afx_stdafx_h__5521fe78_653c_437d_b8e8_cb6f274f39a5__included_)
#define afx_stdafx_h__5521fe78_653c_437d_b8e8_cb6f274f39a5__included_

#if _msc_ver > 1000
#pragma once
#endif // _msc_ver > 1000

#define _win32_winnt 0x403

#include <atlbase.h>
#include <iostream>

#import "c:/program files/simonfell/pocketsoap1.1/psoap32.dll" raw_interfaces_only named_guids no_namespace

// todo: reference additional headers your program requires here

//{{afx_insert_location}}
// microsoft visual c++ will insert additional declarations immediately before the previous line.

#endif // !defined(afx_stdafx_h__5521fe78_653c_437d_b8e8_cb6f274f39a5__included_)
  • 本文來源于網頁設計愛好者web開發社區http://www.html.org.cn收集整理,歡迎訪問。
  • 發表評論 共有條評論
    用戶名: 密碼:
    驗證碼: 匿名發表
    主站蜘蛛池模板: 德格县| 晋江市| 宾阳县| 和平区| 阳山县| 靖边县| 吐鲁番市| 台南县| 朔州市| 东丰县| 弋阳县| 北川| 邵武市| 嘉禾县| 饶河县| 浮梁县| 陇南市| 南皮县| 瓮安县| 长治市| 武强县| 民权县| 仪陇县| 武乡县| 梁山县| 上栗县| 邵阳县| 滦平县| 阳曲县| 浦城县| 福安市| 正定县| 秦安县| 瑞丽市| 高邑县| 仁化县| 铁力市| 邵武市| 舟曲县| 登封市| 郴州市|