tags:

views:

667

answers:

4

I'm throwing together a quick data service in WCF to be accessed by a public Silverlight 2.0 application. As my data is very static and relatively simple I'd like to just store it in local XML files (which is made easier as there are a VERY limited number of people who will ever edit it).

I'm wondering what the best way to find a relative path from within my service will be. In traditional ASP.NET I could use the Server.MapPath....within this WCF service nothing similar is available. This solution will ultimately be hosted at a hosting provider I have no control over so I can't hardcode any fixed locations. I'd much rather just get a relative path to some XML files in my AppData folder.

Any suggestions?

+2  A: 

Try using HostingEnvironment.ApplicationPhysicalPath.

Steve Dignan
+1  A: 

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

Shiraz Bhaiji
A: 

The WCF services still have access to a lot of the same things as your ASP.NET pages (since, in the end there is still an HTTP request and response). You can still use Server.MapPath like so:

HttpContext.Current.Server.MapPath(...)
AgileJon
That will only work if you enable ASP.NET compatibility mode, and unless you want to port an existing ASMX web service to WCF, there's rarely any reason to do that.
Mark Seemann
A: 

First, add an operation to the service to return the current directory. Have the new operation just return Environment.CurrentDirectory. In the client, check to see if you are surprised by what the current directory was. Adjust as needed.

John Saunders