Task: To be able to render a PDF when user clicks a link (which is a WCF Service {example: http://localhost:6186/MyReportServices.svc/reports/012}). The Service goes and fetches the report from SSRS Server and returns the Stream. Here is the piece of code that is in .
[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;
}
}
My Operation Contract looks like:
[OperationContract(Action = "*")]
[WebInvoke(Method = "POST",
UriTemplate = "reports/{value}")]
Stream GetReport(int value);
So far so good. But here is the problem... When i click the link above, i get the following error in a dialog box with title Adobe Reader and message:
File does not begin with '%PDF-'.
Error Image: http://i.imgur.com/A4J68.png
I can save the Memory Stream to a file and manually open the pdf, and it opens just fine without issues.
Thanks.