Rank: Newbie Groups: Member
Joined: 1/7/2015 Posts: 7
|
Hello, I am trying to use Html To Pdf on Azure Cloud Services. It works for a day or two but after that it starts returning timeouts. Even when I send a HTML file with empty body and head. When I delete my deployment and create new one, then it starts working again. My converter code is very simple. This is a commercial product, o I am in quite trouble now. Any help would be appreciated.
Code: C#
[HttpPost]
public HttpResponseMessage HtmlToPdf(HtmlDTO html)
{
try
{
using (var stream = ConvertHtmlToPdf(html))
{
HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK);
response.Content = new ByteArrayContent(stream.ToArray());
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
return response;
}
}
catch(Exception e)
{
HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.BadRequest);
response.Content = new StringContent(e.Message);
return response;
}
}
private MemoryStream ConvertHtmlToPdf(HtmlDTO html)
{
var doc = new PdfDocument();
EO.Pdf.HtmlToPdf.ConvertHtml(html.Html, doc);
var result = new MemoryStream();
doc.Save(result);
return result;
}
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,196
|
Hi,
Your code looks perfectly fine. Do you have the exact timeout error message?
One thing you can try to do in the mean time is to run the HTML to PDF converter in a separate AppDomain, then when the conversion start to fail (for example, when it throws out time out error), you can unload the previous AppDomain and create a new one. This is similar to restart the application. Please download the latest build from our download page when you try this approach as we have just fixed an issue with running the converter in separate AppDomains.
Thanks!
|