title: Return pdf byte array WCF
body: <p>I am using a web service, WCF, to return a PDF file in byte array format. I was just returning the pdf file that I had in resources like this: </p>
  
  <pre><code>public byte[] displayPDF(string pdfName){
      return Service.Properties.Resources.testFile;
  }
  </code></pre>
  
  <p>However on the client side when I receive the byte array and write it to a file on my computer using this:</p>
  
  <pre><code>HttpClient client = new HttpClient();
  client.MaxResponseContentBufferSize = 9999999;
  var uri = new Uri("http://TestSite.azurewebsites.net/Service.svc/webHttp/displayPDF?pdfName=testFile.pdf");
  var response = client.GetAsync(uri);
  byte[] byteArray = response.Result.Content.ReadAsByteArrayAsync().Result;
  var filePath = "C:\\Users\\Admin 1\\Documents\\temp.pdf"; 
  System.IO.File.WriteAllBytes(filePath, byteArray);
  </code></pre>
  
  <p>It writes out a PDF file to My Documents, but when I click on it it says can't view PDF because it is not supported file type or it may be corrupted. </p>
  
  <p>I have seen some posts about instead of sending a byte array, to send it using stream. I was wondering if there was any examples on how to do this properly, so that I can write the byte array or stream or whatever you suggest out to a pdf file on the client side, then manually open the file by clicking on it. </p>
  
  <p><strong>Note:</strong> I am accessing the Web service using REST. So adding a Service Reference is not an option.</p>