在WCF中调用Server.MapPath 获取服务发布目录路径
2012-10-20 15:34
483 查看
在WCF中调用Server.MapPath 获取服务发布目录路径
在WCF中想使用Server.Map获取当前服务发布目录的绝对路径。可是在调试时却发现:
“System.Web.HttpContext.Current.Server.MapPath("..." + filename);”
“当没有开启ASP.NET相容模式时(aspNetCompatibilityEnabled="true"),WCF不支持HttpContext, HttpApplication,大部分文章都建议修改<serviceHostingEnvironment aspNetCompatibilityEnabled="true">使WCF可使用ASP.NET传统做法。”
最后有两种解决方法:
//以上写法在WCF未开aspNetCompatibilityEnabled时,//会因HttpContext.Current == null发生错误
在WCF中想使用Server.Map获取当前服务发布目录的绝对路径。可是在调试时却发现:
“System.Web.HttpContext.Current.Server.MapPath("..." + filename);”
“当没有开启ASP.NET相容模式时(aspNetCompatibilityEnabled="true"),WCF不支持HttpContext, HttpApplication,大部分文章都建议修改<serviceHostingEnvironment aspNetCompatibilityEnabled="true">使WCF可使用ASP.NET传统做法。”
最后有两种解决方法:
string t1 = System.Web.HttpContext.Current.Server.MapPath("~");
//以上写法在WCF未开aspNetCompatibilityEnabled时,//会因HttpContext.Current == null发生错误
string t2 = System.Web.Hosting.HostingEnvironment.MapPath("~");
//以上写法在WCF中使用没有问题 1. Application.StartupPath——获取启动了应用程序的可执行文件的路径,不包括可执行文件的名称。 2. Environment.CurrentDirectory——获取和设置当前目录(即该进程从中启动的目录)的完全限定路径,只是“当前”目录,不一定是exe文件所在的目录。在用FileOpenDialog选择一个文件以后这个目录就跟着发生改变了。 3. Application.ExecutablePath——获取启动了应用程序的可执行文件的路径,包括可执行文件的名称。 4。System.AppDomain.CurrentDomain.BaseDirectory——获取基目录,它由程序集冲突解决程序用来探测程序集。(windows服务中使用)
相关文章推荐
- 在WCF中调用Server.MapPath 获取服务发布目录路径
- 在WCF中调用Server.MapPath 获取服务发布目录路径
- .net通过WCF调用java发布的服务,获取数据
- windows服务等获取文件路径文件目录方法
- windows服务等获取文件路径文件目录方法
- C# 在服务中获取文件根目录(获取根路径)
- 使用GeoServer+OpenLayers发布和调用WMTS、Vector Tile矢量切片服务 | Publishing and Calling WMTS, Vector Tile Service Using GeoServer + OpenLayers
- 不能用 Server.MapPath 的情况下 获取物理路径
- Silverlight调用WCF服务出现The remote server returned an error: NotFound可能原因
- ASP.NET获取各级目录Server.MapPath详解全
- GeoServer基础教程(五):使用OpenLayers调用GeoServer发布的地图服务
- Server.MapPath()获取本机绝对路径
- ASP.NET获取各级目录Server.MapPath详解全
- WCF服务发布和调用IIS服务
- ASP.NET获取各级目录位置Server.MapPath详解全
- 获取当前文件路径或当前打开的文件路径Server.MapPath
- wcf服务发布时,目录中没有文件生成
- 获取.net的根目录的方法 和 Server.MapPath
- 在iis下发布wcf,调用时出现错误--调用方未由服务进行身份验证
- ASP.NET获取各级目录Server.MapPath详解全