HttpListener.EndGetContext(IAsyncResult) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
들어오는 클라이언트 요청을 검색하는 비동기 작업을 완료합니다.
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 클라이언트 요청을 나타내는 개체입니다.
예외
asyncResult 메서드를 호출 BeginGetContext(AsyncCallback, Object) 하여 가져오지 못했습니다.
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 전달됩니다. 개체의 asyncResult 속성을 사용하여 이 상태 개체를 AsyncState 가져올 수 있습니다.
비동기 프로그래밍 모델 사용에 대한 자세한 내용은 동기 메서드를 비동기적으로 호출하는 방법을 참조하세요.
호출자 참고
이 멤버는 애플리케이션에서 네트워크 추적을 사용하도록 설정할 때 추적 정보를 출력합니다. 자세한 내용은 .NET Framework의 네트워크 추적을 참조하세요.