0

I've got a little problem with my WCF service running under the IIS. My service uses third party libraries. This lib for initialization needs the configuration file that contains paths to the query files. Running under the IIS this lib cannot deal with the relative paths of the query files i.e.: .\Config\Lib_query.txt etc. From my understanding reason is that the service is running under do w3wp process. There is no problem with running this on self-host or even in unit tests.

Is there any way of telling IIS to run under different context? Using AppDomain. CurrentDomain. BaseDirectory etc. isn't an option because I have no power inside those libs. So far I was using the fixed path, but we're moving to distributed environment and not replacing path in config path will be a huge convenience.

Kuba
  • 3
  • 1
  • 3
  • 1
    That typically means the library vendor does not test ever against IIS and it was not designed for IIS either. Then you should find another library or force the vendor to provide a solution. – Lex Li Oct 09 '15 at 06:53
  • In near future I can use REST API, but for now isn't an option. But in other hand if I made sth, in for example self-host environment and it's working, I should expect that in a different hosting environment it should work as well but apparently it didn't. – Kuba Oct 09 '15 at 07:09

1 Answers1

0

Assuming the library uses a relative path, you can just chance the directory to the directory your application is in.

See Defining a working directory for executing a program (C#). You can do so in the application start of your global.asax.

Community
  • 1
  • 1
CodeCaster
  • 147,647
  • 23
  • 218
  • 272
  • I think I've tried to change Directory using Directory.SetCurrentDirectory(), but it didn't help. To be sure I'll try to play more with it, and put it in different places. Thanks. – Kuba Oct 09 '15 at 07:15
  • It should work. IIS runs in system32 or inetsrv, that's why the relative path doesn't work initially. Try SetCurrentDirectory with your base directory hardcoded. – CodeCaster Oct 09 '15 at 07:17
  • I put this in Global.asax do some tweaks and its working. Thanks guys. Take care. – Kuba Oct 09 '15 at 07:44