【发布时间】:2014-03-14 20:43:18
【问题描述】:
我正在使用 JQuery 从客户端使用 WCF 服务方法。我想在客户端保存从 WCF 方法返回的流数据。以下 WCF 方法运行良好,其中我使用我们自己的 excelExport 方法创建内存流 -
public System.IO.Stream TestExportToExcel()
{
using (_oxBowData = new Data.OxbowDataContext())
{
ExcelExport excelExport = new ExcelExport();
List<SheetData> sheets = new List<SheetData>();
sheets.Add(new SheetData()
{
SheetName = "sheet1",
DataList = _oxBowData.GetLunchReportData(new DateTime(2013, 12, 24)).ToList<object>()
});
using (MemoryStream xlsstream = excelExport.ExportToExcelToStream(sheets))
{
xlsstream.Position = 0L;
return xlsstream;
}
}
}
服务合同:
[OperationContract]
[WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, UriTemplate = "TestExportToExcel")]
System.IO.Stream TestExportToExcel();
以下是我在客户端使用的,但它只是返回错误-
$.ajax({
type: "GET",
url: u + "/Terminal/ManagementService.svc/TestExportToExcel",
contentType: "application/json; charset=utf-8",
dataType: "json",
processData: false,
success: function (data) {
alert(JSON.stringify(data));
},
error: function (data) {
alert(JSON.stringify(data));
}
});
当我调用这个客户端 ajax 调用时,它会返回错误。有人可以帮忙吗?
【问题讨论】:
-
您能否将请求类型从
"GET"更改为"POST"。在stackoverflow.com/questions/21224781/… 的帖子中阅读