Windows Azure Web ロールでホストされている ASP.NET Web API アプリケーションを使用しています。このアプリケーションの目的は、HTTP 要求を他の Web 対応エンドポイント (Service Bus Relay など) にプロキシし、それらの応答を返すことです。
重要な (>5MB) ペイロードを含むリクエストを送信すると、アプリケーションが例外をスローすることがあります。これは、ペイロードが大きいリクエストの 20 分の 1 で発生する可能性があります。
例外の詳細: System.AggregateException: 1 つ以上のエラーが発生しました。---> System.Web.HttpException: クライアントが切断されました。
System.Web.Hosting.IIS7WorkerRequest.EndRead(IAsyncResult asyncResult) で System.Web.HttpBufferlessInputStream.EndRead(IAsyncResult asyncResult) で System.Net.Http.StreamToStreamCopy.BufferReadCallback(IAsyncResult ar) --- 内部例外スタック トレースの終了 - -- ---> (内部例外 #0) System.Web.HttpException (0x800703E3): クライアントが切断されました。System.Web.Hosting.IIS7WorkerRequest.EndRead(IAsyncResult asyncResult) で System.Web.HttpBufferlessInputStream.EndRead(IAsyncResult asyncResult) で System.Net.Http.StreamToStreamCopy.BufferReadCallback(IAsyncResult ar)<--- ; TraceSource 'w3wp.exe' イベント
これらの Http 要求は、.NET 4.5 の System.Net.HttpClient を使用して送信します。
public class ProxyController : ApiController
{
private static readonly HttpClient HttpClient = new HttpClient();
private static readonly Uri BaseUri = new Uri("http://webendpoint.com");
public HttpResponseMessage Post()
{
var newUri = new Uri(BaseUri, Request.RequestUri.PathAndQuery);
var request = new HttpRequestMessage(HttpMethod.Post, newUri)
{
Content = this.Request.Content
};
var task = HttpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);
task.Wait();
var response = task.Result;
return new HttpResponseMessage(response.StatusCode)
{
Content = new PushStreamContent((stream, content, ctx) =>
{
var tempStream = response.Content.ReadAsStreamAsync().Result;
tempStream.CopyToAsync(stream).Wait();
stream.Flush();
stream.Close();
})
};
}
}
この問題の原因について何か考えはありますか?