I am able to debug in client and the server and quiet sure that its NOT doing it multiple times as it takes one trip to the server and i capture the result on the client side that very time. I tried to dig deeper into the UTF-8 option suggested by lee but couldnt get it working still.
There is also one issue when i try to call the getpdf service method directly from the browser(chrome, IE11, mozilla) then also i get an error. Below is the restful service code
Service method contract definition
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json)]
MemoryStream GetPDF(string empid);
Service Side method Code
public MemoryStream GetPDF(string empid)
{
string pdfName = "myfile.pdf";
byte[] bytes = File.ReadAllBytes(@"C:\working\myfile.pdf");
MemoryStream ms = new MemoryStream();
ms.Write(bytes, 0, bytes.Length - 1);
ms.Position = 0;
WebOperationContext.Current.OutgoingResponse.ContentType = "application/pdf";
WebOperationContext.Current.OutgoingResponse.Headers.Add("Content-disposition", "inline; filename=" + pdfName);
return ms; //ms.Length = 4658228
}
When I am trying to call this method directly from the browser it throws an error like below :

Client Side Electron App Code
const shell = require('electron').shell
var optionsGetPDF = {
host: 'localhost',
port: 8080,
path: '/GetPDF?empid=' + empid.trim(),
method: 'GET'
};
var request = http.request(optionsGetPDF, function (response) {
var data = [];
response.on('data', function (chunk) {
data.push(chunk);
})
response.on('end', function () {
data = Buffer.concat(data);
shell.openItem(data);
})
});
request.end();
I tried other alternative ways on the client side like using memorystream object , piping the response into the fs object , but couldnt get it working.
Please help. Thanks in advance.