如何获取 wcf 应用程序的工作路径? [英] How to get working path of a wcf application?

查看:29
本文介绍了如何获取 wcf 应用程序的工作路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆