Service : WCF REST Service (.Net Framework 4.0)
Platform: 64-bit (Windows)


I have a WCF rest service to fetch data and show it on the client screen. I am using a node js client application which mostly uses javascript to fetch this pdf memory stream and then displays it onto the client machine.

I am trying to read PDF files in the wcf restful service and send it as a memory stream and open the PDF on the client machine and haven't been able to do so by far. Need your help in achieving the same. Below is the code :

WCF Service method contract definition

 MemoryStream  GetPDF(string empid);
WCF Service Side Code

    public MemoryStream  GetPDF(string empid)
        string pdfName ="myfile.pdf";
        byte[] bytes =File.ReadAllBytes(@"C:\working\myfile.pdf");
         have also tried the below code for reading the bytes with different encoding :-
         but even that doesn't work
        MemoryStream ms =new MemoryStream();
        ms.Write(bytes,0, bytes.Length-1);
        WebOperationContext.Current.OutgoingResponse.Headers.Add("Content-disposition","inline; filename="+ pdfName);
        return ms;//ms.Length = 4658228
When I am trying to call this method directly into the browser with the help of the URL it throws an error like below instead it should open the PDF into the browser:

Not sure if that should be the correct behaviour. Could you please let me know whats going wrong here.