HttpListener.EndGetContext(IAsyncResult) Yöntem
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Gelen istemci isteğini almak için zaman uyumsuz bir işlemi tamamlar.
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
Parametreler
- asyncResult
- IAsyncResult
IAsyncResult Zaman uyumsuz işlem başlatıldığında elde edilen nesne.
Döndürülenler
HttpListenerContext İstemci isteğini temsil eden bir nesne.
Özel durumlar
asyncResult yöntemi çağrılarak BeginGetContext(AsyncCallback, Object) elde edilemedi.
asyncResult, null'e eşittir.
Win32 işlev çağrısı başarısız oldu. Özel durumun ErrorCode nedenini belirlemek için özel durumun özelliğini denetleyin.
Yöntemi EndGetContext(IAsyncResult) belirtilen asyncResult nesne için zaten çağrıldı.
Bu nesne kapatıldı.
Örnekler
Aşağıdaki kod örneği, yöntemini çağıran bir geri çağırma yönteminin EndGetContext uygulanmasını gösterir.
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
Açıklamalar
yöntemi EndGetContext , gelen istemci isteğini ve ilişkili yanıtını içeren nesneyi almak HttpListenerContext için genellikle bir temsilci tarafından çağrılan uygulama tanımlı bir geri çağırma yöntemi içinde çağrılır. Bu yöntem, yöntemini çağırarak daha önce başlatılan bir işlemi tamamlar BeginGetContext . İşlem tamamlanmadıysa, bu yöntem tamamlanana kadar engeller.
yöntemini çağırmak EndGetContext nesne gerektirdiğinden HttpListener , bu nesne genellikle yöntemine geçirilen durum nesnesi kullanılarak bir geri çağırma yöntemine BeginGetContext geçirilir. Nesnenin özelliğini asyncResult kullanarak AsyncState bu durum nesnesini alabilirsiniz.
Zaman uyumsuz programlama modelini kullanma hakkında ayrıntılı bilgi için bkz. Zaman Uyumlu Yöntemleri Zaman Uyumsuz Olarak Çağırma.
Arayanlara Notlar
Bu üye, uygulamanızda ağ izlemeyi etkinleştirdiğinizde izleme bilgilerini döndürür. Daha fazla bilgi için bkz. .NET Framework'te Ağ İzleme.