問(wèn)題描述
這篇 MSDN 文章 說(shuō):
HttpContext:從 WCF 服務(wù)中訪問(wèn)時(shí),Current 始終為 null.請(qǐng)改用 RequestContext.
我想要做的是從我的 IIS 托管的 WCF 服務(wù)中加載一些 XSD 文件.問(wèn)題是,我無(wú)法弄清楚如何像在任何舊的香草 ASP.NET 網(wǎng)站中那樣執(zhí)行 Server.MapPath(),例如:
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 托管的 WCF 服務(wù)中使用 RequestContext 的等效方法是什么?
What would be the equivalent way using RequestContext in an IIS hosted WCF service?
架構(gòu)位于服務(wù)應(yīng)用程序根目錄的架構(gòu)"目錄中.使用 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 網(wǎng)站中運(yùn)行良好,而不是在 IIS 托管的 WCF 服務(wù)中.
Which works fine from within a normal ASP.NET website, just not an IIS hosted WCF service.
推薦答案
你可以使用 HostingEnvironment.MapPath.
這篇關(guān)于如何在 WCF 服務(wù)中使用 RequestContext 映射路徑的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!