I use Abcpdf,
Sometimes I get in production FileNotFoundException after creation of HttpMultipartMimeForm with path use by the HttpContent.Create(
methode
The major part of time this code works well
The PDF is creat in context where
- ASP.NET website A is called
- A call website B to generate the PDF
- Website B call url on B for HTML to PDF abcpdf method.
- After previous request to B is finish, website A send file to server C via HttpClient HttpMultipartMimeForm and Exception is throw sometimes, but when I look on the server the file exist
A and B is on the same machine and sharing the same directories.
I supposed that the file is not finish to write on disk when I try to acces on it. But how to resolved this ?
Thanks.
1. Server A
using (HttpClient pdfClient = new HttpClient("http://" + ConfigurationManager.AppSettings["xxx"]))
{
using (HttpResponseMessage message = pdfClient.Get(UrlDictionary.callxxx(xxxID, xxxID)))
{
message.EnsureStatusIsSuccessful();
message.Content.ReadAsStream();
}
}
2. Server B
theDoc.Save(HostingEnvironment.ApplicationPhysicalPath + "/xxx/" + ".pdf");
theDoc.Clear();
3. Server A
HttpMultipartMimeForm request = new HttpMultipartMimeForm();
FileInfo info = new FileInfo(pathFile);
HttpFormFile file = new HttpFormFile();
file.Content = **HttpContent.Create(info, "multipart/form-data")**; (Exception FileNotFoundException)
file.FileName = info.Name;
file.Name = "file";
request.Files.Add(file);
request.Add("id", id);
using (HttpResponseMessage response = client.Post(
string.Format("/xxx/{0}", id),
request.CreateHttpContent()))
{
ExceptionIfBadRequest(response);
Contrat contrat = (Contrat)FromXml(response.Content.ReadAsString(), typeof(Contrat));
return contrat;
}