I have a WCF
service that will receive an id and return a pdf file based off of the id. I am assuming that the best way to do this would be to convert the pdf file to some sort of string and then return it. However, I am unsure of which stream to use (Stream, Filestream, or MemoryStream
).
I know i could read the pdf file to a byte array and then do something with it using MemoryStream, but I feel like there is a more efficient way.
I tried doing what was suggested in this post here: How to convert a pdf to a memory stream
Hard coding a file path in to return like so:
return File(@"C:\MyFile.pdf", "application/pdf");
Just to see what happens, but get an error on File
saying: `'System.IO.File' is a 'type' but is used like a 'variable'.
Would anyone be able to provide a little insight?
EDIT
This is currently what I am working towards:
[OperationContract]
[WebInvoke(Method = "GET",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/GetInvoiceFile")]
Stream GetInvoiceFile(string id);
public Stream GetInvoiceFile(string BillingPeriodId)
{
byte[] bytes = File.ReadAllBytes(@"C:\pdf-test.pdf");
return new MemoryStream(bytes);
}
I just dont exactly know how I would edit my OperationContract
to return the pdf. Any ideas?