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

<script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript"> </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_)

seover="window.status='正文--利用PocketSOAP 链接webservice(2)--- VC++';return true">
<script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript"> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
This is an Open Source [MPL] SOAP client COM component for the Windows family, originally targeted at PocketPC (hence the name), there is also a Win32 version that works on Windows 95/98/Me/NT4/2000/XP/2003. The package includes a HTTP 1.1 transport for making HTTP based SOAP requests, however the transport is separate from the main SOAP core, so any other transports can be easily added. James Clark's excellent Expat XML Parser is used for parsing the response SOAP messages. PocketSOAP includes the following features Support for SOAP 1.1 and SOAP 1.2 SOAP 1.1 Section 5 encoding support, including simple types, base64 binary, arrays, multi-dim arrays, partial & sparse arrays, nil's, complex types, root handling and multi-references (including circular references) Support for document/literal style SOAP services (such as ASP.NET) Attachments support via both DIME and SOAP with Attachments Support for SOAP headers Full support for pluggable serializers, replace any of the standard serializers with your own (e.g. you could provide a serializer that maps collection objects to/from SOAP Arrays). The serializer engine include multi-ref support for both serialization & deserialization. Comes with a propertyBag serializer, serialize any persistant VB object to/from a SOAP complex type out of the box with no extra code !. Support for both 1999 & 2001 Schema versions. Efficient stream based parsing. HTTP 1.1 support including persistent connections, SSL, proxies, authentication, proxy authentication, redirects, cookies and compression.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值