如何获取WCF应用程序的工作路径? [英] How to get working path of a wcf application?
问题描述
我想获取WCF应用程序的工作文件夹.我怎么才能得到它?
I want to get the working folder of a WCF application. How can I get it?
如果我尝试
HttpContext.Current.Request.MapPath(HttpContext.Current.Request.ApplicationPath)
我得到一个空引用异常(Http.Current对象为空).
I get a null reference exception (the Http.Current object is null).
我对工作文件夹的意思是运行WCF服务的文件夹.如果设置aspNetCompatibilityEnabled="true"
,则会出现此错误:
What I meant with the working folder was the folder where my WCF service is running. If I set aspNetCompatibilityEnabled="true"
, I get this error:
服务器未提供有意义的回复;这可能是由于合同不匹配,会话过早关闭或服务器内部错误引起的.
The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error.
推荐答案
对于IIS6托管的WCF应用程序,我需要相同的信息,但我发现这对我有用:
I needed the same information for my IIS6 hosted WCF application and I found that this worked for me:
string apPath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath;
一如既往,YMMV.
这篇关于如何获取WCF应用程序的工作路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!