問題描述
這篇 MSDN 文章 說:
HttpContext:從 WCF 服務中訪問時,Current 始終為 null.請改用 RequestContext.
我想要做的是從我的 IIS 托管的 WCF 服務中加載一些 XSD 文件.問題是,我無法弄清楚如何像在任何舊的香草 ASP.NET 網站中那樣執(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 服務中使用 RequestContext 的等效方法是什么?
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.
這篇關于如何在 WCF 服務中使用 RequestContext 映射路徑的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!