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

<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 728x15, 创建于 08-4-23MSDN */ google_ad_slot = "3624277373"; google_ad_width = 728; google_ad_height = 15; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 160x600, 创建于 08-4-23MSDN */ google_ad_slot = "4367022601"; google_ad_width = 160; google_ad_height = 600; //--> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
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_)
11AI9E9A0A927.jpg
seover="window.status='正文--利用PocketSOAP链接webservice(2)---VC++';return true">
<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 728x15, 创建于 08-4-23MSDN */ google_ad_slot = "3624277373"; google_ad_width = 728; google_ad_height = 15; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 160x600, 创建于 08-4-23MSDN */ google_ad_slot = "4367022601"; google_ad_width = 160; google_ad_height = 600; //--> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
阅读更多
个人分类: .net
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭