static class, used in a webservice, cannot find it's XML file

J

j

I'm using a static class to read (from an XML file) some 'frequently
used' settings that will be shared in both console applications and
web services.
The class works for console applications, butn using the same class in
a web service always results in a FileNotFoundException.

I have verified that the file it needs is in the directory where it is
expecting it, but I still get the same exception.
I added the "HttpContext" line because I'd read somewhere that it was
preferable to "GetExecutingAssembly()" when dealing with web service,
but that didn't work, either.

What is the most reliable way to accomplish this?


FileInfo loc = new
FileInfo(Assembly.GetExecutingAssembly().Location);
FileInfo config = new
FileInfo(Path.Combine(loc.DirectoryName, file));
if (!config.Exists)
{
Logger.writeLog(config.FullName);
config = new
FileInfo(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath,
file));
if (!config.Exists)
{
Logger.writeLog(config.FullName);
throw new
FileNotFoundException(config.FullName);
}
}
_file = config.FullName;


thanks in advance.
 
M

Michael Letterle

I'm using a static class to read (from an XML file) some 'frequently
used' settings that will be shared in both console applications and
web services.
The class works for console applications, butn using the same class in
a web service always results in a FileNotFoundException.

I have verified that the file it needs is in the directory where it is
expecting it, but I still get the same exception.
I added the "HttpContext" line because I'd read somewhere that it was
preferable to "GetExecutingAssembly()" when dealing with web service,
but that didn't work, either.

What is the most reliable way to accomplish this?

FileInfo loc = new
FileInfo(Assembly.GetExecutingAssembly().Location);
FileInfo config = new
FileInfo(Path.Combine(loc.DirectoryName, file));
if (!config.Exists)
{
Logger.writeLog(config.FullName);
config = new
FileInfo(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath,
file));
if (!config.Exists)
{
Logger.writeLog(config.FullName);
throw new
FileNotFoundException(config.FullName);
}
}
_file = config.FullName;

thanks in advance.

Are you sure that the user that the webservice is running as, has read
permission to the file?
 
G

Guest

Try using the more common ASP / ASP.NET convention of
Server.MapPath("yourconfigfile.config")
-- assuming it is in the same folder as the ASMX endpoint file.
Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top