【发布时间】:2011-07-25 16:54:33
【问题描述】:
任务:当用户单击链接时能够呈现 PDF(这是 WCF 服务{示例:http://localhost:6186/MyReportServices.svc/reports/012})。服务从 SSRS 服务器获取报告并返回流。这是 中的一段代码。
[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
public class AssistReportServices : IAssistReportServices
{
public Stream GetReport(int value)
{
//skipped some lines of code.
try
{
result = rs.Render(format, devInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs);
execInfo = rs.GetExecutionInfo();
}
catch (SoapException err)
{
throw;
}
MemoryStream ms = new MemoryStream();
ms.Write(result, 0, result.Length);
ms.Position = 0;
//WebOperationContext.Current.OutgoingResponse.ContentType = ConfigurationManager.AppSettings["ResponseType"];
WebOperationContext.Current.OutgoingResponse.ContentType = "application/pdf";
return ms;
}
}
我的运营合同如下:
[OperationContract(Action = "*")]
[WebInvoke(Method = "POST",
UriTemplate = "reports/{value}")]
Stream GetReport(int value);
到目前为止一切顺利。但问题出在这里...当我单击上面的链接时,我在标题为 Adobe Reader 和消息的对话框中收到以下错误:
文件不以“%PDF-”开头。
错误图片:http://i.imgur.com/A4J68.png
我可以将内存流保存到一个文件并手动打开 pdf,它可以正常打开而没有问题。
谢谢。
【问题讨论】:
-
错误消息看起来更像是一个问题,Acrobat 认为它正在打开一个名为
012而不是名为012.pdf等的文件。