任務:在用戶單擊鏈接(這是WCF服務{例如:http://localhost:6186/MyReportServices.svc/reports/012})時能夠呈現PDF。該服務將從SSRS服務器獲取報告並返回流。這是一段代碼。使用WCF Restful Services的PDF
[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'的文件等。 –