这MSDN article说:
HttpContext:从 WCF 服务中访问时,Current 始终为 null。请改用 RequestContext。
我想做的是从我的 IIS 托管 WCF 服务加载一些 XSD 文件。问题是,我不知道如何像在任何旧的 vanilla ASP.NET 网站中那样执行 Server.MapPath(),例如:
HttpContext.Current.Server.MapPath(schemaUri);
在 IIS 托管的 WCF 服务中使用 RequestContext 的等效方法是什么?
模式位于服务应用程序根目录下的“模式”目录中。它们是使用 web.config 中的自定义配置部分引用的,如下所示:
<schemas>
<add uri="~/Schemas/foo.xsd" xmlNamespace="http://foo.bar/types" />
</schemas>
我试图像这样加载:
var schemaUri = HttpContext.Current.Server.MapPath(schema.Uri);
这在普通的 ASP.NET 网站中运行良好,但不适用于 IIS 托管的 WCF 服务。
最佳答案
您可以使用 HostingEnvironment.MapPath .
关于c# - 如何在 WCF 服务中使用 RequestContext 映射路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10384894/