3
Я использую IHttpHandler для вызова веб-службы и возврата полученного байт [] клиенту в виде загруженного прикрепленного файла. Это прекрасно работает, но когда я попытался изменить IHttpHandler на IHttpAsyncHandler, откроется диалоговое окно загрузки файла, но файл не запускается/не заканчивается загрузкой. Что я делаю не так?Проблема с отправкой файла через IHttpAsyncHandler
<%@ WebHandler Language="C#" Class="PreviewPDF" %>
using System;
using System.Web;
public class PreviewPDF : IHttpAsyncHandler
{
public void ProcessRequest(HttpContext context)
{
}
public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
{
string data = "some data";
using (WebService.RequestService service = new WebService.RequestService())
{
AsyncCallback callback = new AsyncCallback(EndProcessRequest);
return service.BeginGetFile(data, callback, context);
}
}
public void EndProcessRequest(IAsyncResult result)
{
HttpContext context = result.AsyncState as HttpContext;
byte[] wsoutput;
using (WebService.RequestService service = new WebService.RequestService())
{
wsoutput = service.EndGetFile(result);
}
context.Response.ContentType = "application/octet-stream";
context.Response.ContentEncoding = System.Text.Encoding.Unicode;
context.Response.AddHeader("Content-Disposition", "attachment; filename=attachment.pdf");
using (System.IO.MemoryStream ms = new System.IO.MemoryStream(wsoutput))
{
ms.WriteTo(context.Response.OutputStream);
}
context.Response.Flush();
}
public bool IsReusable {
get {
return false;
}
}
}