Export (0) Print
Expand All

IRequestHandler Interface 

This interface provides the methods necessary for a request handler.


__interface ATL_NO_VTABLE
__declspec( uuid( "D57F8D0C-751A-4223-92BC-0B29F65D2453" ))
IRequestHandler :
   public IUnknown

This interface is implemented by IRequestHandlerImpl and, as a consequence, CRequestHandlerT and CSoapHandler.

Header: atlsiface.h

Although it is rare that you'll need to implement this interface yourself, this example shows an IRequestHandler implementation that is independent of CRequestHandlerT:

class CRequestHandler :
    public IRequestHandlerImpl<CRequestHandler>,
    public CComObjectRootEx<CComSingleThreadModel>
{
private:

    CHttpResponse m_HttpResponse;
    CHttpRequest m_HttpRequest;
    bool m_bChildRequest;

public:

    BEGIN_COM_MAP(CRequestHandler)
        COM_INTERFACE_ENTRY(IRequestHandler)
    END_COM_MAP()

    CRequestHandler() :
        m_bChildRequest(false)
    {
    }

    HTTP_CODE GetFlags(LPDWORD pdwStatus)
    {
        *pdwStatus = ATLS_FLAG_NONE;
        return HTTP_SUCCESS;
    }

    HTTP_CODE InitializeChild(
        AtlServerRequest *pRequestInfo, 
        IServiceProvider *pProvider, 
        IHttpRequestLookup *pLookup)
    {
        m_bChildRequest = true;

        // Initialize members inherited from IRequestHandlerImpl.
        m_hInstHandler = pRequestInfo->hInstDll;
        m_spServiceProvider = pProvider;
        if (pRequestInfo->pServerContext)
        {
            m_spServerContext = pRequestInfo->pServerContext;
        }

        HTTP_CODE hcErr = HTTP_SUCCESS;
        if (pLookup != NULL)
        {
            // Initialize the CHttpResponse member.
            BOOL bRet = m_HttpResponse.Initialize(pLookup);
            if (bRet)
            {
                if (m_spServerContext != NULL)
                {
                    bRet = m_HttpResponse.Initialize(m_spServerContext);
                }
                if (bRet)
                {
                    // Initialize the CHttpRequest member.
                    bRet = m_HttpRequest.Initialize(pLookup);
                    if (bRet && m_spServerContext != NULL)
                    {
                        bRet =
                             m_HttpRequest.Initialize(m_spServerContext);
                    }
                }
            }

            if (!bRet)
            {
                hcErr = HTTP_FAIL;
            }
        }

        // Child handlers should not buffer their output.
        m_HttpResponse.SetBufferOutput(FALSE);

        return hcErr;
    }

    HTTP_CODE InitializeHandler(
        AtlServerRequest *pRequestInfo,
        IServiceProvider *pProvider)
    {
        m_bChildRequest = false;

        // Initialize members inherited from IRequestHandlerImpl.
        m_hInstHandler = pRequestInfo->hInstDll;
        m_spServiceProvider = pProvider;
        m_spServerContext = pRequestInfo->pServerContext;

        // Initialize the CHttpResponse member.
        BOOL bRet = m_HttpResponse.Initialize(m_spServerContext);
        if (bRet)
        {
            // Initialize the CHttpRequest member.
            bRet = m_HttpRequest.Initialize(m_spServerContext);
        }

        return bRet ? HTTP_SUCCESS : HTTP_FAIL;
    }

    HTTP_CODE HandleRequest(
        AtlServerRequest *pRequestInfo,
        IServiceProvider *pProvider)
    {
        _ATLTRY
        {
            m_HttpResponse << "<html><body>";
            if (m_bChildRequest)
            {
                m_HttpResponse << "<h1>Child Request</h1>";
            }
            else
            {
                m_HttpResponse << "<h1>Top-Level Request</h1>";
            }
            m_HttpResponse << "</html></body>";
        }
        _ATLCATCHALL()
        {
            return HTTP_ERROR(500, ISE_SUBERR_OUTOFMEM);
        }

        return HTTP_SUCCESS;
    }

    void UninitializeHandler()
    {
        // Flush the response explicitly.
        m_HttpResponse.Flush(TRUE);
    }

}; // class CRequestHandler

Community Additions

ADD
Show:
© 2014 Microsoft