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.
You can use HostingEnvironment.MapPath.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With