Relative WCF Service Paths Hosted in IIS

I am compiling a fast data service in WCF to access a public Silverlight 2.0 application. Since my data is very static and relatively simple, I would just like to save it in local XML files (which was simplified, since there is a VERY limited number of people who will ever edit it).

I am wondering what is the best way to find the relative path from my service. In traditional ASP.NET, I could use Server.MapPath .... nothing like this is available inside this WCF service. This solution will ultimately be hosted by the hosting provider. I cannot control, therefore I cannot fix any fixed locations. I would rather just get the relative path to some XML files in the AppData folder.

Any suggestions?

+7
wcf
source share
5 answers

You can try using Environment.CurrentDirectory or AppDomain.CurrentDomain.BaseDirectory

+11
source share
+4
source share

WCF services still have access to the same things as your ASP.NET pages (since there is still an HTTP request and response at the end). You can still use Server.MapPath like this:

HttpContext.Current.Server.MapPath(...) 
+2
source share

You can store files in IsolatedStorage instead of your application folder. See an example on the linked page to find out how it works.

+1
source share

First add an operation to the service to return the current directory. Ask for a new operation to simply return Environment.CurrentDirectory. In the client, check if your current directory is surprised. Adjust if necessary.

0
source share

All Articles