任务:当用户单击链接时能够呈现 PDF(这是 WCF 服务{示例:http://localhost:6186/MyReportServices.svc/reports/012 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-”开头。
错误图像:https://i.stack.imgur.com/Btiql.png https://i.stack.imgur.com/Btiql.png
我可以将内存流保存到文件中并手动打开 pdf,它打开得很好,没有问题。
Thanks.