Мой метод службы WCF на C#:
Код: Выделить всё
[OperationContract()]
public Stream GetCsvFile(int id)
{
string s = ...;
WebOperationContext.Current.OutgoingResponse.ContentType = "text/csv";
WebOperationContext.Current.OutgoingResponse.Headers["Content-Disposition"] = "attachment; filename=\"file1.csv\"";
return GenerateStreamFromString(s);
}
public Stream GenerateStreamFromString(string s)
{
MemoryStream stream = new MemoryStream();
StreamWriter writer = new StreamWriter(stream);
writer.Write(s);
writer.Flush();
stream.Position = 0;
return stream;
}
Код: Выделить всё
$.ajax({
type: "POST",
url: serviceUrl,
cache: false,
data: data,
dataType: "text",
contentType: "application/json; charset=utf-8",
success: function() {
// TODO...
}
});
В старой версии VB.NET того же приложения в коде программной части страницы .aspx работало следующее:
Код: Выделить всё
Response.Clear()
Response.ContentType = "text/csv"
Response.AddHeader("content-disposition", "attachment; filename="file1.csv")
Response.Write(s)
Response.End()
Так почему же это не работает, когда я пытаюсь вызвать службу WCF с помощью jQuery?
Подробнее здесь: https://stackoverflow.com/questions/150 ... ice-stream
Мобильная версия