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

📄 soapser.cpp

📁 Windows CE 6.0 Server 源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CSoapSerializer::endHeaderElement( void)
{
    return endElement();
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: CSoapSerializer::endHeader()
//
//  parameters:
//
//  description: creates the closing soap-header tag 
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CSoapSerializer::endHeader( void)
{
#ifndef CE_NO_EXCEPTIONS
    try
    {
#endif    
        HRESULT hr = S_OK;
    
        // check the state
        CHK_BOOL (chks(header_opened), E_FAIL);
        CHK(endElement());
    
        m_eState = header_closed;
    
    Cleanup:
        ASSERT(hr==S_OK);
        return (hr);
#ifndef CE_NO_EXCEPTIONS        
    }
    catch (...)
    {
        ASSERTTEXT (FALSE, "CSoapSerializer::endHeader - Unhandled Exception");
        return E_FAIL;
    }
#endif    
}




/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: CSoapSerializer::startBody( BSTR enc_style_uri)
//
//  parameters:
//
//  description: signals the start of the buddy and allows definition of encoding
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CSoapSerializer::startBody( 
    BSTR enc_style_uri)
{
#ifndef CE_NO_EXCEPTIONS
    try
    {
#endif    
        HRESULT    hr;
    
        CHK (Initialized());
        CHK (FlushElement() ); 

        // check the state
        CHK_BOOL (chks(envelope_opened) || chks(header_closed), E_FAIL);
        m_eState = body_opened;
        
        CHK (startElement( (WCHAR *) g_pwstrBody, (WCHAR *)g_pwstrEmpty,  enc_style_uri, m_pcSoapPrefix) );

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

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: CSoapSerializer::endBody()
//
//  parameters:
//
//  description:
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CSoapSerializer::endBody( void)
{
#ifndef CE_NO_EXCEPTIONS
    try
    {
#endif    
        HRESULT hr = S_OK;
    
        // check the state
        CHK_BOOL (chks(body_opened), E_FAIL);
        CHK(endElement());
    
        m_eState = body_closed;
    
    Cleanup:
        ASSERT(hr==S_OK);
        return (hr);
#ifndef CE_NO_EXCEPTIONS       
    }
    catch (...)
    {
        ASSERTTEXT (FALSE, "CSoapSerializer::endBody - Unhandled Exception");
        return E_FAIL;
    }
#endif    
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: CSoapSerializer::startElement(BSTR name, BSTR ns_uri,
//                                          BSTR enc_style_uri, BSTR prefix)
//
//  parameters:
//
//  description: start a element, including namespace and encoding definition
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CSoapSerializer::startElement( 
    BSTR name,
    BSTR ns_uri,
    BSTR enc_style_uri,
    BSTR prefix)

{
#ifndef CE_NO_EXCEPTIONS
    try
    {
#endif    
        HRESULT    hr;
        WCHAR * pPrefix;

        CHK (Initialized());
        CHK (FlushElement() ); 
        TRACEL((2, "%5d: Env::startElement\n", GetCurrentThreadId() ));    
        CHK_BOOL (chks(envelope_opened) || chks(header_opened) || chks(body_opened), E_FAIL);

        if (!prefix)
            prefix = (BSTR) g_pwstrEmpty;
        if (!ns_uri)
            ns_uri = (BSTR) g_pwstrEmpty;
        if (!name)
            name = (BSTR) g_pwstrEmpty;
        if (!enc_style_uri)
            enc_style_uri = (BSTR) g_pwstrNone;

        m_nsHelper.PushLevel();
        
        CHK(PushElement(prefix, name, ns_uri));
        pPrefix = NamespaceHandler(prefix, ns_uri);
        // in any case we have a prefix now, additionaly a namespace declaration
        // has been added to the attribute list by the previous call if it was
        // necessary.

        if (wcscmp(prefix, pPrefix))
        {
            // this should only happen if prefix was ""
            ASSERT (wcslen(prefix) == 0);
            CElementStackEntry * pele;

            pele = PeekElement();
            CHK(pele->setPrefix(pPrefix));
        }

        if (wcsicmp(g_pwstrNone, enc_style_uri))
        {
            // the string is not "NONE", we have to output some attribute
            if (wcsicmp(g_pwstrStandard, enc_style_uri) == NULL)
            {
                // we want the standard encoding style here
                enc_style_uri = (BSTR) g_pwstrEncStyleNS;
            }
            
            // now we have encoding style which is some kind of string, a URL set above, 
            // or even an empty string
            //
            // we can just output it
               CHK (m_ElementStack.AddAttribute(m_pcSoapPrefix, (WCHAR *)g_pwstrEnvNS, (WCHAR *)g_pwstrEncStyle, enc_style_uri) );
        }                    

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





/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: CSoapSerializer::endElement()
//
//  parameters:
//
//  description: no parameter needed, all information is known internally
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CSoapSerializer::endElement( void )
{
#ifndef CE_NO_EXCEPTIONS
    try
    {
#endif    
        HRESULT    hr;
        CAutoP<CElementStackEntry> pele(NULL);
        
        CHK (Initialized());
        CHK (FlushElement() ); 
        TRACEL((2, "%5d: Env::endElement\n", GetCurrentThreadId() ));    
        CHK_BOOL (chks(envelope_opened) || chks(header_opened) || chks(body_opened), E_FAIL);

        pele = PopElement();

        CHK_BOOL (pele != NULL, E_FAIL);
        
        CHK(_WriterEndElement(
            pele->getPrefix(),wcslen((WCHAR *)pele->getPrefix()), 
            pele->getName(),  wcslen((WCHAR *)pele->getName()),
            pele->getQName(), wcslen((WCHAR *)pele->getQName()) ) 
            );
        
        CHK (m_nsHelper.PopLevel());
        
    Cleanup:
        ASSERT(hr==S_OK);
        return (hr);
        
#ifndef CE_NO_EXCEPTIONS       
    }
    catch (...)
    {
        ASSERTTEXT (FALSE, "CSoapSerializer::endHeaderElement - Unhandled Exception");
        return E_FAIL;
    }
#endif    
}





/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: CSoapSerializer::SoapAttribute( BSTR name, BSTR ns_uri,
//                                            BSTR value, BSTR prefix)
//
//  parameters:
//
//  description: add Attribute information to the current element, 
//                the has to happen after the call to startElement.
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CSoapSerializer::SoapAttribute( 
    BSTR name,
    BSTR ns_uri,
    BSTR value,
    BSTR prefix)
{
#ifndef CE_NO_EXCEPTIONS
    try 
    {
#endif    
        HRESULT hr = S_OK;
        WCHAR *    pPrefix;

        CHK_BOOL (chks(envelope_opened) || chks(header_opened) || chks(body_opened), E_FAIL);

        if (!prefix)
            prefix = (BSTR) g_pwstrEmpty;
        if (!ns_uri)
            ns_uri = (BSTR) g_pwstrEmpty;

        pPrefix = NamespaceHandler(prefix, ns_uri);
        // in any case we have a prefix now, additionaly a namespace declaration
        // has been added to the attribute list by the previous call if it was
        // necessary.

        // the attribute is added
        CHK (m_ElementStack.AddAttribute(pPrefix, ns_uri, name, value) );

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

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: CSoapSerializer::SoapNamespace( BSTR prefix, BSTR ns_uri)
//
//  parameters:
//
//  description: 
//
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////

HRESULT CSoapSerializer::SoapNamespace( 
                BSTR prefix,
                BSTR ns_uri)
{
#ifndef CE_NO_EXCEPTIONS
    try 
    {
#endif    
        HRESULT hr = S_OK;

        CHK_BOOL (chks(envelope_opened) || chks(header_opened) || chks(body_opened), E_FAIL);

        // add namespace declaration to the list
        NamespaceHandler(prefix, ns_uri);

    Cleanup:
        ASSERT(hr==S_OK);
        return (hr);
#ifndef CE_NO_EXCEPTIONS       
    }
    catch (...)
    {
        ASSERTTEXT (FALSE, "CSoapSerializer::SoapAttribute - Unhandled Exception");
        return E_FAIL;
    }
#endif    
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: CSoapSerializer::SoapDefaultNamespace( BSTR ns_uri)
//
//  parameters:
//
//  description: 
//                
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CSoapSerializer::SoapDefaultNamespace( 
                BSTR ns_uri)
{
#ifndef CE_NO_EXCEPTIONS
    try 
    {
#endif    
        HRESULT hr = S_OK;
        CElementStackEntry    * pele;
        
        CHK_BOOL (chks(envelope_opened) || chks(header_opened) || chks(body_opened), E_FAIL);

        pele = PeekElement();
        ASSERT (pele);
        
        CHK (pele->setDefaultNamespace(ns_uri));
        CHK (m_ElementStack.AddAttribute((WCHAR *)g_pwstrEmpty, (WCHAR *)g_pwstrEmpty, (WCHAR*)g_pwstrXmlns, ns_uri) );
        
    Cleanup:
        ASSERT(hr==S_OK);
        return (hr);
#ifndef CE_NO_EXCEPTIONS        
    }
    catch (...)
    {
        ASSERTTEXT (FALSE, "CSoapSerializer::SoapAttribute - Unhandled Exception");
        return E_FAIL;
    }
#endif  
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: CSoapSerializer::writeString(BSTR string)
//
//  parameters:
//
//  description: 
//                
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CSoapSerializer::writeString( 
                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);
        
        CHK(_WriterCharacters(string, wcslen(string)) );

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

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: CSoapSerializer::writeBuffer(long len, char * buffer)

⌨️ 快捷键说明

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