Beispiel #1
0
        /// <summary>
        /// Uploads the data into the web request.
        /// </summary>
        /// <param name="request">The request that is setup for a put.</param>
        /// <param name="source">The source of data.</param>
        /// <param name="result">The response from the server.</param>
        /// <returns>The sequence used for uploading data.</returns>
        internal TaskSequence UploadData(HttpWebRequest request, Stream source, Action<WebResponse> result)
        {
            // Retrieve the stream
            var requestStreamTask = request.GetRequestStreamAsyncEx();
            yield return requestStreamTask;

            // Copy the data
            using (var outputStream = requestStreamTask.Result)
            {
                var copyTask = new InvokeTaskSequenceTask(() => { return source.WriteTo(outputStream); });
                yield return copyTask;

                // Materialize any exceptions
                var scratch = copyTask.Result;
							Console.WriteLine(scratch);
            }

            // Get the response
            var responseTask = request.GetResponseAsyncWithTimeout(this.ServiceClient, this.ServiceClient.Timeout);
            yield return responseTask;

            // Return the response object
            var response = responseTask.Result;

            result(response);
        }