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

📄 soapser.cpp

📁 Windows CE 6.0 Server 源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
//
//  parameters:
//
//  description: 
//                
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////       
HRESULT STDMETHODCALLTYPE CSoapSerializer::writeBuffer( 
           long len,
           char * buffer)
{
#ifndef CE_NO_EXCEPTIONS
    try 
    {
#endif    
        HRESULT                hr(S_OK);
#ifndef UNDER_CE        
        ULONG                 ret;
#endif
        ASSERT (buffer);

        

        CHK (Initialized());
        CHK (FlushElement() ); 
        CHK_BOOL (chks(envelope_opened) || chks(header_opened) || chks(body_opened), E_FAIL);

        if (m_bElementOpen)
        {
            // first end the element
            CHK (m_pEncodingStream->write((BSTR)g_pwstrClosing));
            m_bElementOpen = false;        
        }

        CHK (m_pEncodingStream->writeThrough((byte*)buffer, len));

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



/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: CSoapSerializer::startFault(BSTR faultcode, BSTR faultstring,
//                                        BSTR faultactor, BSTR faultcodeNS)
//
//  parameters:
//
//  description:
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CSoapSerializer::startFault( 
    BSTR faultcode,
    BSTR faultstring,
    BSTR faultactor,
    BSTR faultcodeNS)
{
#ifndef CE_NO_EXCEPTIONS
    try 
    {
#endif 
        HRESULT    hr;
        WCHAR * pPrefix = L"";
        
        ASSERT (faultcode);
        ASSERT (faultstring);
        
        CHK (Initialized());
        CHK (FlushElement() ); 
        m_bFaultOccured = TRUE;
        
        CHK_BOOL (chks(body_opened), E_FAIL);

        CHK (startElement((BSTR) g_pwstrFault, (BSTR) g_pwstrEmpty, (BSTR) g_pwstrNone, m_pcSoapPrefix) );
            CHK (startElement((BSTR) g_pwstrFaultcode, (BSTR) g_pwstrEmpty, (BSTR) g_pwstrNone,  0) );

            if ( (faultcodeNS == NULL) || (wcslen(faultcodeNS) == 0) )
            {
                // the namespace we are looking at is empty, we are going
                // with the standard soap namespace
                pPrefix = m_pcSoapPrefix;
            }
            else
            {
                pPrefix = NamespaceHandler((WCHAR *) g_pwstrEmpty, faultcodeNS);
                // in any case we have a prefix now, additionaly a namespace declaration
                // has been added to the attribute list by the call if it was
                // necessary.
            }
            // now write something like:
            //          <pPrefix>:<faultcode>
            // as the actual faultcode
            CHK (writeString(pPrefix));
            CHK (writeString(L":"));
            CHK (writeString(faultcode) );
            CHK (endElement() );
            
            CHK (startElement((BSTR) g_pwstrFaultstring, (BSTR) g_pwstrEmpty, (BSTR) g_pwstrNone, 0) );
            CHK (writeString(faultstring) );
            CHK (endElement() );
            if  ( (faultactor) && (wcslen(faultactor)) )
            {
            CHK (startElement((BSTR) g_pwstrFaultactor, (BSTR) g_pwstrEmpty, (BSTR) g_pwstrNone, 0) );
            CHK (writeString(faultactor) );
            CHK (endElement() );
            }
            
    Cleanup:
        ASSERT(hr==S_OK);
        return (hr);
#ifndef CE_NO_EXCEPTIONS
    }
    catch (...)
    {
        ASSERTTEXT (FALSE, "CSoapSerializer::startFault - Unhandled Exception");
        return E_FAIL;
    }
#endif 
}




/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: CSoapSerializer::startFaultDetail(BSTR enc_style_uri)
//
//  parameters:
//
//  description:
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CSoapSerializer::startFaultDetail (  
                BSTR enc_style_uri)
{
    HRESULT hr = S_OK;
    
    CHK_BOOL (chks(body_opened), E_FAIL);
    
    CHK(startElement((BSTR) g_pwstrDetail, (BSTR) g_pwstrEmpty, enc_style_uri, 0));
Cleanup:
    ASSERT(hr==S_OK);
    return (hr);
}




/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: CSoapSerializer::endFaultDetail()
//
//  parameters:
//
//  description:
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CSoapSerializer::endFaultDetail( void)
{
    HRESULT hr = S_OK;
    
    CHK_BOOL (chks(body_opened), E_FAIL);
    
    CHK(endElement());
Cleanup:
    ASSERT(hr==S_OK);
    return (hr);
}





/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: CSoapSerializer::endFault()
//
//  parameters:
//
//  description:
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CSoapSerializer::endFault(void)
{
    HRESULT hr = S_OK;
    
    CHK_BOOL (chks(body_opened), E_FAIL);
    
    CHK(endElement());
Cleanup:
    ASSERT(hr==S_OK);
    return (hr);
}







/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: CSoapSerializer::reset()
//
//  parameters:
//
//  description:
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CSoapSerializer::reset(void)
{
    HRESULT hr = S_OK;

    if (m_pEncodingStream)
        m_pEncodingStream->Reset();

    m_pcSoapPrefix = NULL;
    m_pcDefaultNamespaceURI = NULL;
    CHK(m_nsHelper.reset());
    CHK(m_ElementStack.reset());
    
    m_eState = created;
    m_bElementOpen = false;
        
Cleanup:
    ASSERT(hr==S_OK);
    return (hr);
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: CSoapSerializer::writeXML( BSTR string)
//
//  parameters:
//
//  description:
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////

HRESULT CSoapSerializer::writeXML( 
                BSTR string)
{
#ifndef CE_NO_EXCEPTIONS
    try 
    {
#endif 
        HRESULT    hr = S_OK;

        ASSERT (string);
        if (!string)
            string = (BSTR)g_pwstrEmpty;

        CHK (Initialized());
        CHK (FlushElement() ); 
        
        CHK_BOOL (chks(envelope_opened) || chks(header_opened) || chks(body_opened), E_FAIL);

        if (m_bElementOpen)
        {
            // first end the element
            CHK (m_pEncodingStream->write((BSTR)g_pwstrClosing));
            m_bElementOpen = false;        
        }
        
        CHK (m_pEncodingStream->write((BSTR)string, wcslen(string)));

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

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: CSoapSerializer::getPrefixForNamespace( BSTR ns, BSTR *prefix)
//
//  parameters:
//
//  description:
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////

HRESULT CSoapSerializer::getPrefixForNamespace( 
            BSTR ns,
            BSTR *prefix)
{
#ifndef CE_NO_EXCEPTIONS
try 
    {
#endif 
        HRESULT    hr = S_OK;
        CNamespaceListEntry    * pEntry = NULL;
    
        ASSERT (ns);
        CHK_BOOL(ns, E_INVALIDARG);
        CHK_BOOL(prefix, E_INVALIDARG);
        CHK_BOOL(wcslen(ns), E_INVALIDARG);
        
        *prefix = NULL;
        
        CHK (Initialized());

        // give as an entry matching this namespace
        pEntry = m_nsHelper.FindNamespace(ns, pEntry);

        // if this entry doesn't exist, we return e_fail and set the return to an empty string
        CHK_BOOL(pEntry, E_FAIL);

        // return the value
        *prefix = ::SysAllocString(pEntry->getPrefix());
        CHK_BOOL(*prefix, E_OUTOFMEMORY);

    Cleanup:
        return (hr);
#ifndef CE_NO_EXCEPTIONS
    }
    catch (...)
    {
        ASSERTTEXT (FALSE, "CSoapSerializer::getPrefix - Unhandled Exception");
        return E_FAIL;
    }
#endif 

}


/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: CSoapSerializer::get_EncodingStream(IUnknown **ppStream)
//
//  parameters:
//
//  description:
//
//  returns a reference to the EncodingSream to the caller
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CSoapSerializer::get_EncodingStream(IUnknown **ppUnknown)
{
#ifndef CE_NO_EXCEPTIONS
    try
    {
#endif 
        HRESULT hr = S_OK;

        CHK_BOOL (ppUnknown, E_INVALIDARG);
        *ppUnknown = NULL; 

        return E_NOTIMPL;

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






/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: CSoapSerializer::Initialized()
//
//  parameters:
//
//  description:
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CSoapSerializer::Initialized()
    {

    HRESULT             hr(S_OK);
#ifndef UNDER_CE    
    ULONG                 ret;
#endif

    if (m_eState > initialized)    
    {
        goto Cleanup;
    }

    // add the default namespace to the list
    m_pcSoapPrefix = (WCHAR *)g_pwstrEnvNS;

    // is the output stream set
    CHK_BOOL ( SUCCEEDED(m_pEncodingStream->IsInitialized()), E_FAIL);

    if (!m_pEncodingStream)
        m_pEncodingStream = new CEncodingStream();
#ifdef CE_NO_EXCEPTIONS
    CHK_BOOL (m_pEncodingStream, E_OUTOFMEMORY);
#endif

    m_eState = initialized;
    
Cleanup:

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



/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: CSoapSerializer::PushElement(WCHAR * pPrefix, WCHAR * pName, WCHAR * pnsURI)
//
//  parameters:
//
//  description:
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

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