Click to Rate and Give Feedback
TechNet
TechNet Library
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2010/.NET Framework 4

Other versions are also available for the following:
.NET Framework Class Library
FtpWebRequest..::.EndGetResponse Method

Ends a pending asynchronous operation started with BeginGetResponse.

Namespace:  System.Net
Assembly:  System (in System.dll)
Visual Basic
Public Overrides Function EndGetResponse ( _
    asyncResult As IAsyncResult _
) As WebResponse
C#
public override WebResponse EndGetResponse(
    IAsyncResult asyncResult
)
Visual C++
public:
virtual WebResponse^ EndGetResponse(
    IAsyncResult^ asyncResult
) override
F#
abstract EndGetResponse : 
        asyncResult:IAsyncResult -> WebResponse 
override EndGetResponse : 
        asyncResult:IAsyncResult -> WebResponse 

Parameters

asyncResult
Type: System..::.IAsyncResult
The IAsyncResult that was returned when the operation started.

Return Value

Type: System.Net..::.WebResponse
A WebResponse reference that contains an FtpWebResponse instance. This object contains the FTP server's response to the request.
ExceptionCondition
ArgumentNullException

asyncResult is nullNothingnullptra null reference (Nothing in Visual Basic).

ArgumentException

asyncResult was not obtained by calling BeginGetResponse.

InvalidOperationException

This method was already called for the operation identified by asyncResult.

WebException

An error occurred using an HTTP proxy.

If the operation has not completed at the time the EndGetResponse method is called, EndGetResponse blocks until the operation completes. To prevent blocking, check the IsCompleted property before calling EndGetResponse.

In addition to the exceptions noted in "Exceptions," EndGetResponse rethrows exceptions that were thrown while communicating with the server.

NoteNote

This member outputs trace information when you enable network tracing in your application. For more information, see Network Tracing.

Notes to Callers

This method generates network traffic.

The following code example demonstrates ending an asynchronous operation to get a response. This code example is part of a larger example provided for the FtpWebRequest class overview.

Visual Basic
' The EndGetResponseCallback method  
' completes a call to BeginGetResponse.
Private Shared Sub EndGetResponseCallback(ByVal ar As IAsyncResult)
    Dim state As FtpState = CType(ar.AsyncState, FtpState)
    Dim response As FtpWebResponse = Nothing
    Try
        response = CType(state.Request.EndGetResponse(ar), FtpWebResponse)
        response.Close()
        state.StatusDescription = response.StatusDescription
        ' Signal the main application thread that 
        ' the operation is complete.
        state.OperationComplete.Set()
        ' Return exceptions to the main application thread.
    Catch e As Exception
        Console.WriteLine("Error getting response.")
        state.OperationException = e
        state.OperationComplete.Set()
    End Try
End Sub
C#
// The EndGetResponseCallback method  
// completes a call to BeginGetResponse.
private static void EndGetResponseCallback(IAsyncResult ar)
{
    FtpState state = (FtpState) ar.AsyncState;
    FtpWebResponse response = null;
    try 
    {
        response = (FtpWebResponse) state.Request.EndGetResponse(ar);
        response.Close();
        state.StatusDescription = response.StatusDescription;
        // Signal the main application thread that 
        // the operation is complete.
        state.OperationComplete.Set();
    }
    // Return exceptions to the main application thread.
    catch (Exception e)
    {
        Console.WriteLine ("Error getting response.");
        state.OperationException = e;
        state.OperationComplete.Set();
    }
}
Visual C++
// The EndGetResponseCallback method  
// completes a call to BeginGetResponse.
static void EndGetResponseCallback( IAsyncResult^ ar )
{
   FtpState^ state = dynamic_cast<FtpState^>(ar->AsyncState);
   FtpWebResponse ^ response = nullptr;
   try
   {
      response = dynamic_cast<FtpWebResponse^>(state->Request->EndGetResponse( ar ));
      response->Close();
      state->StatusDescription = response->StatusDescription;

      // Signal the main application thread that 
      // the operation is complete.
      state->OperationComplete->Set();
   }
   // Return exceptions to the main application thread.
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "Error getting response." );
      state->OperationException = e;
      state->OperationComplete->Set();
   }
}

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker