473,385 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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.

Apr 9 '07 #1
2 1639
On Apr 9, 1:26 pm, "j" <mr.jawri...@gmail.comwrote:
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?

Apr 9 '07 #2
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

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"j" wrote:
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.

Apr 9 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: DanielBradley | last post by:
Hello all, I have recently been porting code from Linux to cygwin and came across a problem with static const class members (discussed below). I am seeking to determine whether I am programming...
1
by: ffhansix | last post by:
Hi, I am having problems with generating a c# proxy class from a IBM websphere WSDL file, when running the wsdl.exe to create the c# proxy file command i recieve an error: Warning: one or...
5
by: | last post by:
Hi, How long do webservice objects live for? In particular, if i have static variables filled with data from a static constructor in a webservice, how long will that data persist? thxs
7
by: Morgan Cheng | last post by:
In the book *Programming C#* 4th editionby Jesse Liberty, it reads "Actually, the CLR guarantees to start running the static constructor before anything else is done with your class. However, it...
1
by: Jon Ebersole | last post by:
I am developing a webservice and a windows application that talk to each other. They are using a standard VB class library in the background. I am having problems understanding why I can't sync my...
14
by: Jeroen | last post by:
Hi all, I've got a question about writing a library. Let me characterize that library by the following: * there is a class A which is available to the user * there is a class B that is used...
9
by: None | last post by:
Hi, I'm facing a problem with static instances. I have created a class called CustomList by deriving the class List<int>. Inside the CustomList i have created Remove event (when any item is...
14
by: Jess | last post by:
Hello, I learned that there are five kinds of static objects, namely 1. global objects 2. object defined in namespace scope 3. object declared static instead classes 4. objects declared...
8
by: cj | last post by:
I've seen examples of web services written with <%@ WebService Language ="Vb" Class=".... at the top. Is it not used in VB 2008?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.