HttpListener.EndGetContext(IAsyncResult) 메서드

정의

들어오는 클라이언트 요청을 검색하기 위한 비동기 작업을 완료합니다.

public:
 System::Net::HttpListenerContext ^ EndGetContext(IAsyncResult ^ asyncResult);
public System.Net.HttpListenerContext EndGetContext (IAsyncResult asyncResult);
member this.EndGetContext : IAsyncResult -> System.Net.HttpListenerContext
Public Function EndGetContext (asyncResult As IAsyncResult) As HttpListenerContext

매개 변수

asyncResult
IAsyncResult

비동기 작업을 시작할 때 가져온 IAsyncResult 개체입니다.

반환

클라이언트 요청을 나타내는 HttpListenerContext 개체입니다.

예외

BeginGetContext(AsyncCallback, Object) 메서드를 호출하여 asyncResult를 가져오지 못한 경우

asyncResult이(가) null인 경우

Win32 함수 호출이 실패한 경우. 예외의 ErrorCode 속성을 검토하여 예외의 원인을 확인할 수 있습니다.

EndGetContext(IAsyncResult) 메서드가 지정된 asyncResult 개체에 대해 이미 호출된 경우

이 개체가 닫혀 있는 경우

예제

다음 코드 예제에서는 호출 하는 콜백 메서드의 구현을 보여 주는 EndGetContext 메서드입니다.

public static void ListenerCallback(IAsyncResult result)
{
    HttpListener listener = (HttpListener) result.AsyncState;
    // Call EndGetContext to complete the asynchronous operation.
    HttpListenerContext context = listener.EndGetContext(result);
    HttpListenerRequest request = context.Request;
    // Obtain a response object.
    HttpListenerResponse response = context.Response;
    // Construct a response.
    string responseString = "<HTML><BODY> Hello world!</BODY></HTML>";
    byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
    // Get a response stream and write the response to it.
    response.ContentLength64 = buffer.Length;
    System.IO.Stream output = response.OutputStream;
    output.Write(buffer,0,buffer.Length);
    // You must close the output stream.
    output.Close();
}
Public Shared Sub ListenerCallback(ByVal result As IAsyncResult)
    Dim listener As HttpListener = CType(result.AsyncState, HttpListener)
    ' Call EndGetContext to complete the asynchronous operation.
    Dim context As HttpListenerContext = listener.EndGetContext(result)
    Dim request As HttpListenerRequest = context.Request
    ' Obtain a response object.
    Dim response As HttpListenerResponse = context.Response
    ' Construct a response.
    Dim responseString As String = "<HTML><BODY> Hello world!</BODY></HTML>"
    Dim buffer As Byte() = System.Text.Encoding.UTF8.GetBytes(responseString)
    ' Get a response stream and write the response to it.
    response.ContentLength64 = buffer.Length
    Dim output As System.IO.Stream = response.OutputStream
    output.Write(buffer, 0, buffer.Length)
    ' You must close the output stream.
    output.Close()
End Sub

설명

합니다 EndGetContext 메서드는, 일반적으로 가져오려고은 대리자를 호출한 애플리케이션에서 정의 된 콜백 메서드 내는 HttpListenerContext 들어오는 클라이언트 요청 및 연결 된 응답을 포함 하는 개체입니다. 이 메서드는 메서드를 호출하여 이전에 시작된 작업을 완료합니다 BeginGetContext . 작업이 완료되지 않은 경우 이 메서드는 작업이 완료될 때까지 차단합니다.

메서드를 EndGetContext 호출하려면 개체가 HttpListener 필요하므로 이 개체는 일반적으로 메서드에 전달된 상태 개체를 사용하여 콜백 메서드로 BeginGetContext 전달됩니다. 개체의 속성을 사용하여 이 상태 개체를 AsyncStateasyncResult 가져올 수 있습니다.

비동기 프로그래밍 모델 사용에 대한 자세한 내용은 동기 메서드 비동기 호출을 참조하세요.

호출자 참고

애플리케이션에 네트워크 추적을 사용하도록 설정하면 이 멤버에서 추적 정보를 출력합니다. 자세한 내용은 .NET Framework 네트워크 추적을 참조하세요.

적용 대상