IGlobalRSCAQueryProvider 인터페이스

IIS Run-Time 상태 및 제어 정보 쿼리에 대한 지원을 추가하여 IHttpEventProvider 인터페이스를 확장합니다.

구문

class IGlobalRSCAQueryProvider : public IHttpEventProvider  

메서드

다음 표에서는 인터페이스에서 노출하는 메서드를 나열합니다 IGlobalRSCAQueryProvider .

속성 Description
GetFunctionName 이벤트를 발생시킨 동적 함수 호출의 이름을 반환합니다.
GetFunctionParameters 이벤트를 발생시킨 동적 함수 호출의 매개 변수를 반환합니다.
GetOutputBuffer BYTE 배열을 만듭니다.
ResizeOutputBuffer 출력 BYTE 배열의 크기를 조정하고 반환합니다.
SetErrorStatus ( IHttpEventProvider에서 상속됩니다.)
SetResult 내부 버퍼를 완료합니다.

파생 클래스

이 인터페이스에는 파생 클래스가 없습니다.

설명

GL_RSCA_QUERY 이벤트에 등록하는 CGlobalModule 파생 클래스는 CGlobalModule::OnGlobalRSCAQueryvirtual 메서드에 대한 매개 변수로 포인터를 받 IGlobalRscaQueryProvider 습니다.

예제

다음 코드 예제에서는 이벤트를 수신 대기하는 전역 모듈을 만드는 방법을 보여 줍니다 GL_RSCA_QUERY . 그런 다음 이벤트 뷰어 정보를 씁니다IGlobalRSCAQueryProvider.

주의

IIS 7은 이벤트 뷰어 많은 수의 이벤트를 생성합니다. 프로덕션 환경에서 로그 오버플로 오류를 방지하려면 일반적으로 이벤트 로그에 캐시 정보를 쓰지 않아야 합니다. 데모를 위해 이 코드 예제에서는 디버그 모드에서만 이벤트 뷰어 항목을 씁니다.

#define _WINSOCKAPI_
#include <windows.h>
#include <sal.h>
#include <tchar.h>
#include <httpserv.h>

#include <string>
using namespace std;

// The CConvert class mirrors the Convert class that is 
// defined in the .NET Framework. It converts primitives 
// and other data types to wstring types.
class CConvert
{
public:
    // The ToByteString converts a double-byte 
    // character string to a single-byte string.
    // str: the double-byte string to convert.
    // return: a single-byte string copied from str.
    static string ToByteString(const wstring& str)
    {
        // Get the length of the 
        // double-byte string.
        size_t length = str.length();

        // Create a temporary char pointer.
        char* byteChar = new char[length+1];
        byteChar[0] = '\0';
        // Copy the double-byte character string
        // into the single-byte string.        
        size_t charsReturned = 0;
        wcstombs_s(&charsReturned, byteChar, 
                   length+1, str.c_str(), length+1);
        // Create a string to return.
        string retString = byteChar;
        // Delete the temporary string and
        // set that string to NULL.
        delete[] byteChar;
        byteChar = NULL;

        // Return the single-byte string.
        return retString;
    }
};

// The CEventWriter class writes XML 
// documents and strings to the event log.
class CEventWriter
{
public:
    // Creates the CEventWriter class.
    // name: the name of the 
    // event log to open.
    CEventWriter(const wstring& name)
    {                
        #ifdef UNICODE
        m_eventLog = RegisterEventSource(NULL, name.c_str());
        #else
        string multiName = CConvert::ToByteString(name);
        m_eventLog = RegisterEventSource(NULL, multiName.c_str());
        #endif        
    }

    // Creates the destructor for the 
    // CEventWriter class. This destructor
    // closes the HANDLE to the event 
    // log if that HANDLE is open.
    virtual ~CEventWriter()
    {
        // If the HANDLE to the event 
        // log is open, close it.
        if (NULL != m_eventLog)
        {
            // Deregister the event log HANDLE.
            DeregisterEventSource(m_eventLog);
            // Set the HANDLE to NULL.
            m_eventLog = NULL;
        }
    }

    // The ReportInfo method writes 
    // a wstring to the event log.
    // info: the wstring to write.
    // return: true if the event log is written.
    BOOL ReportInfo(const wstring& info)
    {
        return ReportEvent(EVENTLOG_INFORMATION_TYPE, info);
    }
protected:
    // The ReportEvent method accepts an event type
    // and a wstring, and attempts to write that 
    // event to the event log.
    // type: the type of the event.
    // data: the wstring to write to the event log.
    // return: true if the event log is written;
    // otherwise, false.
    BOOL ReportEvent(WORD type, const wstring& data)
    {
        // If the m_eventLog HANDLE 
        // is NULL, return false.
        if (NULL == m_eventLog)
        {
            return FALSE;
        }

        #ifndef _DEBUG
        // If the current build is not debug,
        // return so the event log is not written.
        return TRUE;
        #endif

        #ifdef UNICODE
        // The unicode version of the ReportEvent
        // method requires double-byte strings.
        PCWSTR arr[1];
        arr[0] = data.c_str();
        return ::ReportEvent(m_eventLog,
                             type,
                             0, 0, NULL, 1, 
                             0, arr, (void*)arr);
        #else
        // The non-unicode version of the ReportEvent
        // method requires single-byte strings.
        string multiByte = 
            CConvert::ToByteString(data);
        LPCSTR arr[1];
        arr[0] = multiByte.c_str();
        return ::ReportEvent(m_eventLog,
                             type,
                             0, 0, NULL, 1,
                             0, arr, (void*)arr);
        #endif
    }
private:
    // Specify the HANDLE to the 
    // event log for writing.
    HANDLE m_eventLog;
};

// The CRSCAGlobalModule class creates the CGlobalModule 
// class and registers for GL_RSCA_QUERY and events.
class CRSCAGlobalModule : public CGlobalModule
{
public:
    // Creates the destructor for the 
    // CGlobalCacheModule class.
    virtual ~CRSCAGlobalModule()
    {

    }
    
    // The RegisterGlobalModule method creates and registers 
    // a new CRSCAGlobalModule for GL_RSCA_QUERY events.
    // dwServerVersion: the current server version.
    // pModuleInfo: the current IHttpModuleRegistrationInfo pointer.
    // pGlobalInfo: the current IHttpServer pointer.
    // return: E_INVALIDARG if the IHttpServer pointer
    // is NULL; ERROR_NOT_ENOUGH_MEMORY if the heap is out of 
    // memory; otherwise, the value from the call to the 
    // SetGlobalNotifications method on the pModuleInfo pointer.
    static HRESULT RegisterGlobalModule
    (
        DWORD dwServerVersion,
        IHttpModuleRegistrationInfo* pModuleInfo,
        IHttpServer* pGlobalInfo
    )
    {        
        // The pGlobalInfo parmeter must be 
        // non-NULL because the constructor 
        // for the CGlobalCacheModule class 
        // requires a non-NULL pointer to a 
        // valid IHttpServer pointer.
        if (NULL == pGlobalInfo)
        {
            return E_INVALIDARG;
        }

        // Create a new CGlobalCacheModule pointer.
        CRSCAGlobalModule* rscaModule = 
            new CRSCAGlobalModule();

        // Return an out-of-memory error 
        // if the traceModule is NULL 
        // after the call to the new operator.
        if (NULL == rscaModule)
        {            
            return HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
        }        

        // Attempt to set global notification 
        // for GL_RSCA_QUERY events by using 
        // the rscaModule as a listener.
        HRESULT hr = pModuleInfo->SetGlobalNotifications
            (rscaModule, GL_RSCA_QUERY);

        // Return the HRESULT from the call to 
        // the SetGlobalNotifications method.
        return hr;
    }

    // The OnGlobalRSCAQuery method is the event 
    // handler method for the GL_RSCA_QUERY event.
    // pProvider: the IGlobalRSCAQueryProvider pointer.
    // return: GL_NOTIFICATION_CONTINUE.
    virtual GLOBAL_NOTIFICATION_STATUS OnGlobalRSCAQuery
    (
        IN IGlobalRSCAQueryProvider* pProvider
    )
    {
        // Return GL_NOTIFICATION_CONTINUE if the
        // IGlobalRSCAQueryProvider pointer is NULL.
        if (NULL == pProvider)
        {
            return GL_NOTIFICATION_CONTINUE;
        }

        // Get the name of the function from
        // the IGlobalRSCAQueryProvider pointer.
        wstring functionName = 
            pProvider->GetFunctionName();

        // Write the function name 
        // information to the event writer.
        m_eventWriter.ReportInfo
            (L"Function Name:  " + functionName);

        // Get the parameters from the 
        // IGlobalRSCAQueryProvider pointer.
        wstring parameters = 
            pProvider->GetFunctionParameters();
        
        // Write the parameter information
        // to the event writer.
        m_eventWriter.ReportInfo
            (L"Parameters:  " + parameters);
        
        // Return GL_NOTIFICATION_CONTINUE so
        // other listeners will receive this event.
        return GL_NOTIFICATION_CONTINUE;
    }

    // The Terminate method is a pure virtual 
    // method that all non-abstract CGlobalModule
    // classes must implement. Calls delete on this.
    virtual VOID Terminate(VOID)
    {
        delete this;
    }
protected:
    // Creates the CRSCAGlobalModule class.
    // Initializes the CEventWriter to write
    // to the event log using the IISADMIN key.
    CRSCAGlobalModule() : m_eventWriter(L"IISADMIN")
    {

    }
private:
    // Specify the CEventWriter writer.
    CEventWriter m_eventWriter;
};

// The RegisterModule method is the 
// main entry point for the DLL.
// dwServerVersion: the current server version.
// pModuleInfo: the current 
// IHttpModuleRegistrationInfo pointer.
// pGlobalInfo: the current IHttpServer pointer.
// return: the value returned by calling the
// CRSCAGlobalModule::RegisterGlobalModule
// method.
HRESULT
__stdcall
RegisterModule(
    DWORD dwServerVersion,
    IHttpModuleRegistrationInfo* pModuleInfo,
    IHttpServer* pGlobalInfo
)
{        
    // Call the static method for initialization.
    return CRSCAGlobalModule::RegisterGlobalModule            
        (dwServerVersion, 
         pModuleInfo, 
         pGlobalInfo);             
}

네이티브 DLL 모듈을 만들고 배포하는 방법에 대한 자세한 내용은 연습: 네이티브 코드를 사용하여 Request-Level HTTP 모듈 만들기를 참조하세요.

위의 코드는 데이터 상자에 다음과 유사한 문자열이 포함된 이벤트 뷰어 애플리케이션 로그에 두 개의 새 이벤트를 씁니다.

Function Name: PMH_App_Domain_Enum_V1  
Parameters:  

필요에 따라 각 함수에 대한 호출 규칙을 명시적으로 선언하는 대신 __stdcall (/Gz) 호출 규칙을 사용하여 코드를 컴파일할 수 있습니다.

상속 계층 구조

IHttpEventProvider

IGlobalRSCAQueryProvider

요구 사항

형식 Description
클라이언트 - Windows Vista의 IIS 7.0
- Windows 7의 IIS 7.5
- Windows 8의 IIS 8.0
- WINDOWS 10 IIS 10.0
서버 - Windows Server 2008의 IIS 7.0
- Windows Server 2008 R2의 IIS 7.5
- Windows Server 2012의 IIS 8.0
- Windows Server 2012 R2의 IIS 8.5
- WINDOWS SERVER 2016 IIS 10.0
제품 - IIS 7.0, IIS 7.5, IIS 8.0, IIS 8.5, IIS 10.0
- IIS Express 7.5, IIS Express 8.0, IIS Express 10.0
헤더 Httpserv.h

참고 항목

웹 서버 코어 인터페이스