In ASP.NET WebForms 4.5, I have a WebAPI controller with a GET method to receive a PDF file.
Then in the business layer of the application, I have an API class with a method that contains the logic for actually searching and returning the PDF file to the controller.
So, the MyController class has:
public HttpResponseMessage GetStatement(string acctNumber, string stmtDate) {
MyApi myApi = new MyApi();
HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
FileStream stream = myApi.GetStatement(acctNumber, stmtDate);
...set the response.Content = stream...
... set the mime type..
... close the stream...
return response;
}
And the MyApi class has:
public FileStream GetStatement(string acctNumber, string stmtDate) {
... makes an HttpWebRequest to get a PDF from another system ...
HttpWebRequest req = WebRequest.Create(......)....
FileStream stream = new FileStream(accountNumber +"_" + stmtDate + ".pdf", FileMode.Create);
response.GetResponseStream().CopyTo(stream);
return stream;
}
The API class is not at the web tier of the application because it is used by other (not web parts) software.
As far as I understand, I do not see the explicit closing of the FileStream in the API method. I could do this in the Controller method, but I would rely on others to do the same when they call it from other areas.
PDF API? , - ? .
-