/// <summary>Ends an asynchronous request for a <see cref="T:System.IO.Stream" /> instance that the application uses to write data.</summary> /// <returns>A <see cref="T:System.IO.Stream" /> object that the application uses to write data.</returns> /// <param name="asyncResult">An <see cref="T:System.IAsyncResult" /> that references the pending request for a stream. </param> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="asyncResult" /> is null. </exception> public override Stream EndGetRequestStream(IAsyncResult asyncResult) { if (asyncResult == null) { throw new ArgumentNullException("asyncResult"); } if (!asyncResult.IsCompleted) { asyncResult.AsyncWaitHandle.WaitOne(); } AsyncResult asyncResult2 = (AsyncResult)asyncResult; FileWebRequest.GetRequestStreamCallback getRequestStreamCallback = (FileWebRequest.GetRequestStreamCallback)asyncResult2.AsyncDelegate; return(getRequestStreamCallback.EndInvoke(asyncResult)); }
/// <summary>Begins an asynchronous request for a <see cref="T:System.IO.Stream" /> object to use to write data.</summary> /// <returns>An <see cref="T:System.IAsyncResult" /> that references the asynchronous request.</returns> /// <param name="callback">The <see cref="T:System.AsyncCallback" /> delegate. </param> /// <param name="state">An object that contains state information for this request. </param> /// <exception cref="T:System.Net.ProtocolViolationException">The <see cref="P:System.Net.FileWebRequest.Method" /> property is GET and the application writes to the stream. </exception> /// <exception cref="T:System.InvalidOperationException">The stream is being used by a previous call to <see cref="M:System.Net.FileWebRequest.BeginGetRequestStream(System.AsyncCallback,System.Object)" />. </exception> /// <exception cref="T:System.ApplicationException">No write stream is available. </exception> /// <PermissionSet> /// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" /> /// </PermissionSet> public override IAsyncResult BeginGetRequestStream(AsyncCallback callback, object state) { if (string.Compare("GET", this.method, true) == 0 || string.Compare("HEAD", this.method, true) == 0 || string.Compare("CONNECT", this.method, true) == 0) { throw new ProtocolViolationException("Cannot send a content-body with this verb-type."); } lock (this) { if (this.asyncResponding || this.webResponse != null) { throw new InvalidOperationException("This operation cannot be performed after the request has been submitted."); } if (this.requesting) { throw new InvalidOperationException("Cannot re-call start of asynchronous method while a previous call is still in progress."); } this.requesting = true; } FileWebRequest.GetRequestStreamCallback getRequestStreamCallback = new FileWebRequest.GetRequestStreamCallback(this.GetRequestStreamInternal); return(getRequestStreamCallback.BeginInvoke(callback, state)); }