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

📄 soapreader.cpp

📁 Windows CE 6.0 Server 源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
        return(E_INVALIDARG);
    if (m_bstrSoapAction.Len())
    {
        *pbstrSoapAction = ::SysAllocString(m_bstrSoapAction);
        if (!*pbstrSoapAction)
            return(E_OUTOFMEMORY);
    }
    else
    {
        *pbstrSoapAction = 0;
    }
    return(S_OK);
}




////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CSoapReader::get_RPCStruct(IXMLDOMElement **ppElement)
//
//  parameters:
//
//  description:
//
//  returns:
//
/////////////////////////////////////////////////////////////
HRESULT CSoapReader::get_RPCStruct( IXMLDOMElement **ppElement )
{
#ifndef CE_NO_EXCEPTIONS
    try
    {
#endif 
        HRESULT                     hr(S_OK);

        CHK ( DOMElementLookup( pMySelectionNS,
                                p_getRPCStruct,
                                ppElement ) );

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



////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CSoapReader::get_RPCParameter(BSTR LocalName, BSTR NamespaceURI,
//                                                  IXMLDOMElement **ppElement)
//
//  parameters:
//
//  description:
//
//  returns:
//
/////////////////////////////////////////////////////////////
HRESULT CSoapReader::get_RPCParameter( BSTR LocalName, BSTR NamespaceURI,
                                       IXMLDOMElement **ppElement)
{
#ifndef CE_NO_EXCEPTIONS
    try {
#else
    __try {
#endif 
        HRESULT         hr(S_OK);
        WCHAR *         pSelectionNS;
        WCHAR *         pXPath;

        if (ppElement == NULL)
            return E_INVALIDARG;

        if (!LocalName)
            return E_INVALIDARG;

        if (NamespaceURI ==NULL)
            NamespaceURI = (BSTR)g_pwstrEmpty;

        // build the selcection namespace of the form:
        //  xmlns:CRS=<envelopens>[ xmlns:CRS2=<NamespaceURI>]        
        if (wcslen(NamespaceURI))
        {
#ifdef UNDER_CE
            size_t cbSelectionNS = sizeof(WCHAR) * (8 + wcslen(pget_HeaderEntryNS) + wcslen(NamespaceURI));
            pSelectionNS = (WCHAR *) _alloca(cbSelectionNS);
            hr = StringCbCopy(pSelectionNS, cbSelectionNS, pget_HeaderEntryNS);
            if(FAILED(hr))
            {
                goto Cleanup;
            }

            hr = StringCbCat(pSelectionNS, cbSelectionNS, NamespaceURI);
            if(FAILED(hr))
            {
                goto Cleanup;
            }

            hr = StringCbCat(pSelectionNS, cbSelectionNS, L"\"");
            if(FAILED(hr))
            {
                goto Cleanup;
            }
#else
            pSelectionNS = (WCHAR *) _alloca(sizeof(WCHAR) * (8 + wcslen(pget_HeaderEntryNS) +
                                                              wcslen(NamespaceURI) ) );
            wcscpy(pSelectionNS, pget_HeaderEntryNS);
            wcscat(pSelectionNS, NamespaceURI);
            wcscat(pSelectionNS, L"\"");
#endif
        }
        else
        {
#ifdef UNDER_CE
            size_t cbSelectionNS = sizeof(WCHAR) * (1 + wcslen(pMySelectionNS));
            pSelectionNS = (WCHAR *) _alloca(cbSelectionNS);
            hr = StringCbCopy(pSelectionNS, cbSelectionNS, pMySelectionNS);
            if(FAILED(hr))
            {
                goto Cleanup;
            }
#else
            pSelectionNS = (WCHAR *) _alloca(sizeof(WCHAR) * (1 + wcslen(pMySelectionNS)));
            wcscpy(pSelectionNS, pMySelectionNS);
#endif
        }

        // build the xpath expression of the form
        //      CSR:Body/*[1]/[CSR2:]<LocalName>
#ifdef UNDER_CE
        size_t cbXPath = sizeof(WCHAR) * (8 + wcslen(p_getRPCParameter) + wcslen(LocalName));
        pXPath = (WCHAR *) _alloca(cbXPath);
        if (wcslen(NamespaceURI))
        {
            hr = StringCbCopy(pXPath, cbXPath, p_getRPCParameter);
            if(FAILED(hr))
            {
                goto Cleanup;
            }
        }
        else
        {
             hr = StringCbCopy(pXPath, cbXPath, p_getRPCParameter2);
            if(FAILED(hr))
            {
                goto Cleanup;
            }
        }

        hr = StringCbCat(pXPath, cbXPath, LocalName);
        if(FAILED(hr))
        {
            goto Cleanup;
        }
#else
        pXPath = (WCHAR *) _alloca(2 * (8 + wcslen(p_getRPCParameter) +
                                             wcslen(LocalName) ) );
        if (wcslen(NamespaceURI))
        {
            wcscpy(pXPath, p_getRPCParameter);
        }
        else
        {
             wcscpy(pXPath, p_getRPCParameter2);
        }
        wcscat(pXPath, LocalName);
#endif

        CHK ( DOMElementLookup( pSelectionNS,
                                pXPath,
                                ppElement ) );

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


////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CSoapReader::get_RPCResult(IXMLDOMElement **ppElement)
//
//  parameters:
//
//  description:
//
//  returns:
//
/////////////////////////////////////////////////////////////
HRESULT CSoapReader::get_RPCResult( IXMLDOMElement **ppElement )
{
#ifndef CE_NO_EXCEPTIONS
    try
    {
#endif 
        HRESULT                     hr(S_OK);

        CHK ( DOMElementLookup( pMySelectionNS,
                                pget_RPCResult,
                                ppElement ) );

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






///////////////////////////////////////////////////////////////////////////////
//  function: HRESULT FillDomMemberVar(void)
//
//  parameters:
//
//  description:
//        Fills the member variable with a DOM pointer if currently uninitialized
//
//  returns:
//
///////////////////////////////////////////////////////////////////////////////
HRESULT CSoapReader::FillDomMemberVar(void)
{
    HRESULT         hr(S_OK);
    VARIANT_BOOL    vb(-1);


    if (m_pDOMDoc == NULL)
    {
#ifndef UNDER_CE 
        // no DOM - we have to create one
        CHK ( CoCreateInstance(CLSID_FreeThreadedDOMDocument30, NULL, 
                        CLSCTX_INPROC_SERVER, IID_IXMLDOMDocument2, (void**)&m_pDOMDoc) );
#else
        CHK ( CoCreateInstance(CLSID_DOMDocument, NULL, 
               CLSCTX_INPROC_SERVER, IID_IXMLDOMDocument2, (void**)&m_pDOMDoc) );               
       
        CHK(m_pDOMDoc->put_resolveExternals(false));            
    
#endif
        CHK ( m_pDOMDoc->put_preserveWhiteSpace(vb) );
    }

Cleanup:
    ASSERT(hr==S_OK);
    return (hr);
}


///////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT DOMElementLookup(const WCHAR * pSelectionNS, const WCHAR * pXpath,
//                                     IXMLDOMElement **ppElement)
//
//  parameters:
//      pNamespace  - the namespace used in the xpath
//      pURI        - the URI for this namespace
//      pXPath      - the xpath expression used
//
//  description:
//        Do a XPath Element lookup in the XML document
//
//      to look up the Envelope definition in the XML document:
//
//      DOMElementLookup( L"xmlns:CSR=\"http://schemas.xmlsoap.org/soap/envelope/\"",
//                        L"CSR:Envelope",
//                        ppElement ) );
//
//  returns:
//
///////////////////////////////////////////////////////////////////////////////
HRESULT CSoapReader::DOMElementLookup( const WCHAR * pSelectionNS,
            const WCHAR * pXpath, IXMLDOMElement **ppElement)
{
    HRESULT                     hr(S_OK);
    CAutoRefc<IXMLDOMNode>         pNode;

    XPathState  xp;

    CHK_BOOL(m_pDOMDoc, E_FAIL);
    CHK_BOOL(ppElement, E_INVALIDARG);
    *ppElement = NULL;

    CHK (xp.initDOMDocument(m_pDOMDoc));
    CHK (xp.addNamespace(pSelectionNS));

    CHK ( m_pDOMDoc->selectSingleNode((BSTR) pXpath, &pNode) );

    if (pNode)
        CHK (pNode->QueryInterface(IID_IXMLDOMElement, (void **)ppElement));
Cleanup:
    return (hr);
}


///////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT DOMNodeListLookup(const WCHAR * pSelectionNS, const WCHAR * pXpath,
//                                      IXMLDOMNodeList **ppNodeList)
//
//  parameters:
//      pNamespace  - the namespace used in the xpath
//      pURI        - the URI for this namespace
//      pXPath      - the xpath expression used
//
//  description:
//        Do a XPath Element lookup in the XML document
//
//      to look up the Envelope definition in the XML document:
//
//      DOMElementLookup( L"xmlns:CSR=\"http://schemas.xmlsoap.org/soap/envelope/\"",
//                        L"CSR:Envelope",
//                        ppElement ) );
//
//  returns:
//
///////////////////////////////////////////////////////////////////////////////
HRESULT CSoapReader::DOMNodeListLookup( const WCHAR * pSelectionNS,
            const WCHAR * pXpath, IXMLDOMNodeList **ppNodeList)
{
    HRESULT hr(S_OK);
    XPathState xp;

    CHK_BOOL(m_pDOMDoc, E_FAIL);
    CHK_BOOL(ppNodeList != NULL, E_INVALIDARG);
    *ppNodeList = NULL;

    CHK (xp.initDOMDocument(m_pDOMDoc));
    CHK (xp.addNamespace(pSelectionNS));

    CHK ( m_pDOMDoc->selectNodes((BSTR) pXpath, ppNodeList) );

Cleanup:
    return (hr);
}




///////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT getFaultXXX(IXMLDOMElement **ppElement, const WCHAR * element)
//
//  parameters:
//      ppElement  - the return node
//      element    - the element we are looking for
//
//  description:
//
//  returns:
//
///////////////////////////////////////////////////////////////////////////////
HRESULT CSoapReader::getFaultXXX( 
            IXMLDOMElement **ppElement,
            const WCHAR * element)
{
    HRESULT hr  = S_OK;
    WCHAR * pCombinedXPath;

    // build the xpath expression of the form
    //      pXpath[CSR:]element
#ifndef UNDER_CE
    pCombinedXPath = (WCHAR *) _alloca(sizeof(WCHAR) * (wcslen(pget_FaultStr) + wcslen(element) + 10 /*+ wcslen(pMyPrefix) */) );
#else
    size_t cchCombinedXPath = wcslen(pget_FaultStr) + wcslen(element) + 10;
#ifdef CE_NO_EXCEPTIONS
        pCombinedXPath = new WCHAR[cchCombinedXPath];
        cchCombinedXPath *= sizeof(WCHAR);
        if(!pCombinedXPath)
            return E_OUTOFMEMORY;
#else
    cchCombinedXPath *= sizeof(WCHAR);
    try{
       pCombinedXPath = (WCHAR *) _alloca(cchCombinedXPath);
    }
    catch(...){
        return E_OUTOFMEMORY;
    }
#endif
#endif
    // build the path without the prefix
#ifdef UNDER_CE
    hr = StringCbCopy(pCombinedXPath, cchCombinedXPath, pget_FaultStr);
    if(FAILED(hr))
    {
        return hr;
    }

    hr = StringCbCat(pCombinedXPath, cchCombinedXPath, element);
    if(FAILED(hr))
    {
        return hr;
    }
#else
    wcscpy(pCombinedXPath, pget_FaultStr);
    wcscat(pCombinedXPath, element);
#endif

    hr =DOMElementLookup( pMySelectionNS, pCombinedXPath, ppElement );
    if (SUCCEEDED(hr) && (ppElement))
#ifdef CE_NO_EXCEPTIONS
        {
            delete [] pCombinedXPath;
            return hr;
        }
#else
        return hr;
#endif

    // we did not find it with the xpath without a prefix, try with a prefix
#ifdef UNDER_CE
    hr = StringCbCopy(pCombinedXPath, cchCombinedXPath, pget_FaultStr);
    if(FAILED(hr))
    {
        return hr;
    }

    hr = StringCbCat(pCombinedXPath, cchCombinedXPath, pMyPrefix);
    if(FAILED(hr))
    {
        return hr;
    }

    hr = StringCbCat(pCombinedXPath, cchCombinedXPath, L":");
    if(FAILED(hr))
    {
        return hr;
    }

    hr = StringCbCat(pCombinedXPath, cchCombinedXPath, element);
    if(FAILED(hr))
    {
        return hr;
    }
#else
    wcscpy(pCombinedXPath, pget_FaultStr);
    wcscat(pCombinedXPath, pMyPrefix);
    wcscat(pCombinedXPath, L":");
    wcscat(pCombinedXPath, element);
#endif

#ifdef CE_NO_EXCEPTIONS
    hr = DOMElementLookup( pMySelectionNS, pCombinedXPath, ppElement );
    delete [] pCombinedXPath;
    return hr;
#else
    return DOMElementLookup( pMySelectionNS, pCombinedXPath, ppElement );
#endif
}


// End Of File

⌨️ 快捷键说明

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