problem writing xml to file with .net mvc - timeout?
Posted
by Mark
on Stack Overflow
See other posts from Stack Overflow
or by Mark
Published on 2010-03-22T13:35:08Z
Indexed on
2010/03/22
14:11 UTC
Read the original article
Hit count: 313
Hey, so having an issue with writing out to an xml file. Works fine for single requests via the browser, but when I use something like Charles to perform 5-10 repeated requests concurrently several of them will fail. The trace simply shows a 500 error with no content inside, basically I think they start timing out waiting for write access or something...
This method is inside my repository class, have also attempted to have repository instance as a singleton but doesn't appear to make any difference..
Any help would be much appreciated. Cheers
public void Add(Request request) {
try {
XDocument requests;
XmlReader xmlReader;
using (xmlReader = XmlReader.Create(_requestsFilePath)) {
requests = XDocument.Load(xmlReader);
XElement xmlRequest = new XElement("request",
new XElement("code", request.code),
new XElement("date", request.date),
new XElement("email", new XCData(request.email)),
new XElement("name", new XCData(request.name)),
new XElement("recieveOffers", request.recieveOffers)
);
requests.Root.Element("requests").Add(xmlRequest);
xmlReader.Close();
}
requests.Save(_requestsFilePath);
} catch (Exception ex) {
HttpContext.Current.Trace.Warn("Error writing to file: "+ex);
}
}
© Stack Overflow or respective owner