如何使用RequestContext的MapPath方法在WCF服务 [英] How to MapPath with RequestContext in WCF Service
问题描述
这 MSDN文章说:
的HttpContext:从WCF服务中访问时,电流总是空。使用的RequestContext代替。
我试图做的是加载从我的IIS托管WCF服务的一些XSD文件。问题是,我无法弄清楚如何做一个使用Server.Mappath()就像我会在任何旧香草ASP.NET网站,是这样的:
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);
什么是一个IIS使用RequestContext的等效方式托管WCF服务?
What would be the equivalent way using RequestContext in an IIS hosted WCF service?
该模式是位于架构目录中的服务应用程序的根目录。他们使用的自定义配置部分在这样的web.config中引用的:
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>
和我试图加载这样的:
VAR schemaUri = HttpContext.Current.Server.MapPath(schema.Uri);
工作正常从一个正常的ASP.NET网站中,只是没有一个IIS托管WCF服务。
Which works fine from within a normal ASP.NET website, just not an IIS hosted WCF service.
推荐答案
您可以使用的HostingEnvironment.MapPath 。
这篇关于如何使用RequestContext的MapPath方法在WCF服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!