This MSDN article says:
HttpContext: Current is always null when accessed from within a WCF service. Use RequestContext instead.
What I’m trying to do is load some XSD files in from my IIS hosted WCF service. Problem is, I can’t figure out how to do a Server.MapPath() like I would in any old vanilla ASP.NET website, something like:
HttpContext.Current.Server.MapPath(schemaUri);
What would be the equivalent way using RequestContext in an IIS hosted WCF service?
The schemas are located in a “Schemas” directory at the root of the service application. They’re referenced using a custom config section in the web.config like this:
<schemas>
<add uri="~/Schemas/foo.xsd" xmlNamespace="http://foo.bar/types" />
</schemas>
And I was trying to load like this:
var schemaUri = HttpContext.Current.Server.MapPath(schema.Uri);
Which works fine from within a normal ASP.NET website, just not an IIS hosted WCF service.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
You can use HostingEnvironment.MapPath.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0