我有一个服务器端 ASP.NET WebMethod (System.Web.Services.WebMethod)。它是通过 JavaScript 从客户端调用的。它使用 System.Net.WebClient 通过其 URL 下载 SSRS 报告,将报告转换为字节数组并将其传递回客户端。这适用于最多 11,089,998 字节的报告,但超过 11,089,999 字节的任何内容(例如 11,089,999 字节)都会向 JavaScript 返回空值。我需要返回一个 11,711,711 字节的报告,并且可能会增加,但最多不超过 13 MB。
在 Web.config 中,我有:
<system.web>
<httpRuntime targetFramework="4.5" maxRequestLength="2097151" executionTimeout="3600"/>
</system.web>
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="2147483647" />
</webServices>
</scripting>
</system.web.extensions>
以下是 WebMethod 的相关行:
[System.Web.Services.WebMethod]
public static byte[] DownloadReport(string opt, string type, string arg)
{
byte[] report = new byte[0];
// Misc code to get the SSRS URL
using (System.Net.WebClient client = new System.Net.WebClient())
{
client.UseDefaultCredentials = true;
byte[] data = client.DownloadData(url);
string path = HttpContext.Current.Server.MapPath(fileName);
File.WriteAllBytes(path, data);
using (FileStream fs = File.Open(path, FileMode.Open, FileAccess.Read))
{
report = new byte[fs.Length];
fs.Read(report, 0, (int)fs.Length);
}
File.Delete(path);
}
return report;
}
这是 JavaScript PageMethod 调用和回调:
PageMethods.DownloadReport(opt, type, arg, DownloadReportCallback, ReportErrors);
function DownloadReportCallback(results) {
var bytes = new Uint16Array(results.length);
for (var i = 0; i < results.length; i++) {
bytes[i] = results[i];
}
var file = new Blob([bytes], { type: mime });
// For IE10+
if (window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveOrOpenBlob(file, name);
}
// For other browsers.
else {
var a = document.createElement("a"),
url = URL.createObjectURL(file);
a.href = url;
a.download = name;
document.body.appendChild(a);
a.click();
setTimeout(function () {
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
}, 0);
}
}
我已经尝试过,但似乎无法让它适用于大于 11,089,998 字节的报告。有人有什么想法吗?感谢您的时间。