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

📄 soapreader.cpp

📁 Windows CE 6.0 Server 源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft shared
// source or premium shared source license agreement under which you licensed
// this source code. If you did not accept the terms of the license agreement,
// you are not authorized to use this source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the SOURCE.RTF on your install media or the root of your tools installation.
// THE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
//+----------------------------------------------------------------------------
//
//
// File:    soapreader.cpp
//
// Contents:
//
// implementation file
//
// ISoapReader Interface implemenation
//
//
//-----------------------------------------------------------------------------
#include "headers.h"
#include "soaprdr.h"
#include "xpathutil.h"
#include "mssoap.h"
#include "soapglo.h"


#ifdef UNDER_CE
#include "WinCEUtils.h"
#include "strsafe.h"
#endif


TYPEINFOIDS(ISoapReader, MSSOAPLib)

BEGIN_INTERFACE_MAP(CSoapReader)
    ADD_IUNKNOWN(CSoapReader, ISoapReader)
    ADD_INTERFACE(CSoapReader, ISoapReader)
    ADD_INTERFACE(CSoapReader, IDispatch)
END_INTERFACE_MAP(CSoapReader)

const WCHAR *       pMySelectionNS      = L"xmlns:CSR=\"http://schemas.xmlsoap.org/soap/envelope/\"";
const WCHAR *       pMyPrefix           = L"CSR";
const WCHAR *       pMyPrefix2          = L"CSR2";
const WCHAR *       pget_Envelope       = L"//CSR:Envelope";
const WCHAR *       pget_Body           = L"//CSR:Envelope/CSR:Body";
const WCHAR *       pget_Header         = L"//CSR:Envelope/CSR:Header";
const WCHAR *       pget_Header2        = L"//CSR:Envelope/CSR:Header/";
const WCHAR *       pget_Fault          = L"//CSR:Envelope/CSR:Body/CSR:Fault";
const WCHAR *       pget_FaultStr       = L"//CSR:Envelope/CSR:Body/CSR:Fault/";
const WCHAR *       pget_HeaderEntryNS  = L"xmlns:CSR=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:CSR2=\"";
const WCHAR *       pget_HeaderEntry    = L"//CSR:Envelope/CSR:Header/CSR2:";
const WCHAR *       pget_MustUnderstand = L"//CSR:Envelope/CSR:Header/*[@CSR:mustUnderstand=\"1\"]";
const WCHAR *       pget_HeaderEntries  = L"//CSR:Envelope/CSR:Header/*";
const WCHAR *       pget_BodyEntries    = L"//CSR:Envelope/CSR:Body/*";
const WCHAR *       pget_BodyEntry      = L"//CSR:Envelope/CSR:Body/CSR2:";
const WCHAR *       pget_BodyEntry2     = L"//CSR:Envelope/CSR:Body/";
const WCHAR *       pget_RPCResult      = L"//CSR:Envelope/CSR:Body/*[1]/*";
const WCHAR *       p_getRPCStruct      = L"//CSR:Envelope/CSR:Body/*[1]";
const WCHAR *       p_getRPCParameter   = L"//CSR:Envelope/CSR:Body/*[1]/CSR2:";
const WCHAR *       p_getRPCParameter2  = L"//CSR:Envelope/CSR:Body/*[1]/";

////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: CSoapReader::CSoapReader()
//
//  parameters:
//
//  description:
//        Constructor
//  returns:
//
////////////////////////////////////////////////////////////////////////////////////////////////////
CSoapReader::CSoapReader()
{
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: CSoapReader::~CSoapReader()
//
//  parameters:
//
//  description:
//        Destructor
//  returns:
//
////////////////////////////////////////////////////////////////////////////////////////////////////
CSoapReader::~CSoapReader()
{
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CSoapReader::load(VARIANT xmlSource, BSTR  bstrSoapAction,
//                                      VARIANT_BOOL *isSuccessful)
//
//  parameters:
//
//  description:
//
//  returns:
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CSoapReader::load( VARIANT  xmlSource, BSTR  bstrSoapAction, VARIANT_BOOL  *isSuccessful )
{
#ifndef CE_NO_EXCEPTIONS
    try
#else
    __try
#endif 
    {   
        HRESULT hr = S_OK;
#ifndef CE_NO_EXCEPTIONS
        CAutoRefc<IRequest> pRequest;
#else
        IRequest *pRequest = NULL;
#endif 

        CHK( FillDomMemberVar() );
        CHK ( m_pDOMDoc->load(xmlSource, isSuccessful) );

        if (bstrSoapAction && ::SysStringLen(bstrSoapAction)>0)
        {
            CHK(UnescapeUrl(bstrSoapAction, &m_bstrSoapAction));
        }
        else
        {
            // now see if we got a IRequest object, and if so, get the soapaction header
            if (V_VT(&xmlSource)==VT_DISPATCH || V_VT(&xmlSource)==VT_UNKNOWN)
            {
                if (V_VT(&xmlSource)==VT_DISPATCH)
                {
                    hr = V_DISPATCH(&xmlSource)->QueryInterface(IID_IRequest, (void ** )&pRequest);
                }
                else
                {
                    hr = V_UNKNOWN(&xmlSource)->QueryInterface(IID_IRequest, (void**)&pRequest);
                }
                if (SUCCEEDED(hr) && pRequest)
                {
                    CHK(RetrieveSoapAction(pRequest));
                }
                hr = S_OK;
            }

        }

    Cleanup:
#ifndef CE_NO_EXCEPTIONS
        if(pRequest)
            pRequest->Release();
#endif 
        ASSERT (hr == S_OK);
        return hr;
    }
#ifndef CE_NO_EXCEPTIONS       
    catch (...)
#else
    __except(1)
#endif    
    {
#ifndef CE_NO_EXCEPTIONS
        if(pRequest)
            pRequest->Release();
#endif 
        ASSERTTEXT (FALSE, "CSoapReader::load - Unhandled Exception");
        return E_FAIL;
    }

}
/////////////////////////////////////////////////////////////////////////////////////////////////////////



/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CSoapReader::loadXML(BSTR bstrXML, VARIANT_BOOL *isSuccessful)
//
//  parameters:
//
//  description:
//
//  returns:
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CSoapReader::loadXML( BSTR bstrXML, VARIANT_BOOL *isSuccessful )
{
#ifndef CE_NO_EXCEPTIONS
    try
    {
#endif
        HRESULT hr = S_OK;

        CHK (FillDomMemberVar());

        CHK ( m_pDOMDoc->loadXML(bstrXML, isSuccessful) );

    Cleanup:
        ASSERT (hr == S_OK);
        return hr;
#ifndef CE_NO_EXCEPTIONS       
    }
    catch (...)
    {
        ASSERTTEXT (FALSE, "CSoapReader::loadXML - Unhandled Exception");
        return E_FAIL;
    }
#endif    
}






/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CSoapReader::RetrieveSoapAction(IRequest *pRequest)
//
//
//  parameters:
//
//  description:
//
//  returns:
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CSoapReader::RetrieveSoapAction( IRequest *pRequest )
{
    CAutoRefc<IRequestDictionary>   pDictionary;
    HRESULT hr = S_OK;
    CVariant vHTTPHeader;
    CVariant vValue;

    CHK (pRequest->get_ServerVariables(&pDictionary));
    CHK (vHTTPHeader.Assign(L"HTTP_SoapAction"));
    CHK (pDictionary->get_Item(vHTTPHeader, &vValue));
    
    CHK (VariantChangeType(&vValue, &vValue, 0, VT_BSTR));

  
    if (::SysStringLen(V_BSTR(&vValue))>0)
    {
        WCHAR *pchWalk=NULL;
        WCHAR *pchTarget=NULL;

        CHK(UnescapeUrl(V_BSTR(&vValue), &m_bstrSoapAction));

        // the soapaction property is most likely enclosed in quotationmarks... remove them...
        pchWalk = m_bstrSoapAction;
        pchTarget = pchWalk;
        while (pchWalk && *pchWalk)
        {
            if (*pchWalk != '\'' && *pchWalk != '"')
            {
                *pchTarget=*pchWalk;
                pchTarget++;
            }
            pchWalk++;
        }
        // zero terminate
        *pchTarget=0;
    }

Cleanup:
    ASSERT(SUCCEEDED(hr));
    return(hr);
}



////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CSoapReader::get_DOM(IUnknown **pXMLDOMDocument)
//
//  parameters:
//
//  description:
//
//  returns:
//
/////////////////////////////////////////////////////////////
HRESULT CSoapReader::get_DOM( IXMLDOMDocument **pIXMLDOMDocument )
{
#ifndef CE_NO_EXCEPTIONS
    try
    {
#endif    
        HRESULT hr = S_OK;

        CHK_BOOL(pIXMLDOMDocument != NULL, E_INVALIDARG);
        CHK(FillDomMemberVar());

        CHK(m_pDOMDoc->QueryInterface(IID_IXMLDOMDocument, (void**) pIXMLDOMDocument));

    Cleanup:
        ASSERT(hr==S_OK);
        return (hr);
 #ifndef CE_NO_EXCEPTIONS
    }
    catch (...)
    {
        ASSERTTEXT (FALSE, "CSoapReader::get_DOM - Unhandled Exception");
        return E_FAIL;
    }
 #endif   
}


////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CSoapReader::get_Envelope(IXMLDOMElement **ppElement)
//
//  parameters:
//
//  description:
//
//  returns:
//
/////////////////////////////////////////////////////////////
HRESULT CSoapReader::get_Envelope( IXMLDOMElement **ppElement )
{
#ifndef CE_NO_EXCEPTIONS  
    try
    {
#endif    
        return  ( DOMElementLookup( pMySelectionNS,
                                pget_Envelope,
                                ppElement ) );
#ifndef CE_NO_EXCEPTIONS                                
    }
    catch (...)
    {
        ASSERTTEXT (FALSE, "CSoapReader::get_Envelope - Unhandled Exception");
        return E_FAIL;
    }
#endif   
}


////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CSoapReader::get_Body(IXMLDOMElement **ppElement)
//
//  parameters:
//
//  description:
//
//  returns:
//
/////////////////////////////////////////////////////////////
HRESULT CSoapReader::get_Body( IXMLDOMElement **ppElement )
{
#ifndef CE_NO_EXCEPTIONS   
    try
    {
#endif
        return ( DOMElementLookup( pMySelectionNS,
                                pget_Body,
                                ppElement ) );
#ifndef CE_NO_EXCEPTIONS                                  
    }
    catch (...)
        {
        ASSERTTEXT (FALSE, "CSoapReader::get_Body - Unhandled Exception");
        return E_FAIL;
        }
#endif        
}


////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CSoapReader::get_Header(IXMLDOMElement **ppElement)
//
//  parameters:
//
//  description:
//
//  returns:
//
/////////////////////////////////////////////////////////////
HRESULT CSoapReader::get_Header( IXMLDOMElement **ppElement )
{
#ifndef CE_NO_EXCEPTIONS   
    try
    {
#endif    
        return (DOMElementLookup( pMySelectionNS,
                                pget_Header,
                                ppElement ) );
#ifndef CE_NO_EXCEPTIONS                                  
    }
    catch (...)
        {
        ASSERTTEXT (FALSE, "CSoapReader::get_Header - Unhandled Exception");
        return E_FAIL;
        }
#endif        
}

////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CSoapReader::get_Fault(IXMLDOMElement **ppElement)
//
//  parameters:
//
//  description:
//
//  returns:
//
/////////////////////////////////////////////////////////////
HRESULT CSoapReader::get_Fault( IXMLDOMElement **ppElement )
{
#ifndef CE_NO_EXCEPTIONS   
    try
    {
#endif    
        return ( DOMElementLookup( pMySelectionNS,
                                pget_Fault,
                                ppElement ) );
#ifndef CE_NO_EXCEPTIONS                                 
    }
    catch (...)
        {
        ASSERTTEXT (FALSE, "CSoapReader::get_Fault - Unhandled Exception");
        return E_FAIL;
        }
#endif       
}



////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CSoapReader::get_FaultString(IXMLDOMElement **ppElement)
//
//  parameters:
//
//  description:
//
//  returns:
//
/////////////////////////////////////////////////////////////
HRESULT CSoapReader::get_FaultString( IXMLDOMElement **ppElement )
{
#ifndef CE_NO_EXCEPTIONS 
    try
    {
#endif 
        return getFaultXXX (ppElement, g_pwstrFaultstring);
#ifndef CE_NO_EXCEPTIONS 
    }
    catch (...)
        {
        ASSERTTEXT (FALSE, "CSoapReader::get_FaultString - Unhandled Exception");
        return E_FAIL;
        }
#endif 
}


////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CSoapReader::get_FaultCode(IXMLDOMElement **ppElement)
//
//  parameters:
//
//  description:
//
//  returns:
//
/////////////////////////////////////////////////////////////
HRESULT CSoapReader::get_FaultCode( IXMLDOMElement **ppElement )
{
#ifndef CE_NO_EXCEPTIONS 
    try
    {

⌨️ 快捷键说明

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