Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to MapPath with RequestContext in WCF Service

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.

like image 521
Didaxis Avatar asked Apr 30 '12 13:04

Didaxis


1 Answers

You can use HostingEnvironment.MapPath.

like image 194
Nick Butler Avatar answered Nov 11 '22 10:11

Nick Butler