Boardy
Boardy

Reputation: 36223

Reading a XML config file in soap

Hi am currently working on a c#/soap/php project. The soap service has a config.xml which contains certain options for use within the soap service and c# program that makes use of the soap service.

It is reading the config if I put it in a certain place instead of it being read from where the config file is. FYI my project is to run on Linux under mono as well as windows.

My soap service is running at, on linux, /srv/www/htdocs/mywebsite/mysoapservice/Service.asmx and the config.xml is within this directory.

On windows its in c:\inetpub\wwwroot\mysoapservice\Service.asmx and the config.xml is within this directory.

When I am reading in the config I don't provide the path to the file I just give it the filename config.xml expecting to retrieve the file where the asmx file is located. However on linux it is trying to get it from root i.e. the config file is at /config.xml and it is read from there, I can't remember the exact path where the config file thinks it should be, forgot to make a note of it but its somewhere deep within the PC not where I am running the service from.

I have tried using Directory.getCurrentDirectory() + "config.xml" but this doesn't work, on Linux seems to think that it is a unc path and that I should use it in the form of \server\share, I don't know why it thinks its a unc path, can't remember the error on windows. That will teach me not to make a note on stuff.

How can I get it to read the config file from the same directory that the asmx file is in.

Thanks for any help you can provide.

Upvotes: 2

Views: 557

Answers (1)

Neil
Neil

Reputation: 1633

I believe that you want to do something like this:

  string applicationPath = HttpContext.Current.Server.MapPath(null);
  string configPath = Path.Combine(applicationPath, "config.xml");

Upvotes: 1

Related Questions