试图让HostingEnvironment.MapPath()
与我的WCF应用程序一起工作时遇到一些问题。在WCF应用程序中返回null的HostingEnvironment.MapPath(路径)
我创建了一个类的静态方法来检查,看看是否HttpContext.Current
为null:
public class ServerPath
{
public static string MapPath(string path)
{
string result;
if (HttpContext.Current != null)
result = HttpContext.Current.Server.MapPath(path);
result = HostingEnvironment.MapPath(path);
return result;
}
}
,一切都通过我在它只是返回null(ServerPath.MapPath(~/file.xml")
和Server.PathPath("./file.xml")
)。如果有人想知道为什么我有'字符串结果';这是因为我添加了if (string.IsNullOrEmpty(result))
并添加了result = Directory.GetCurrentDirectory() + path;
当使用WCF测试客户端进行测试时,是否有其他人遇到类似问题?
请让我知道它是否与绑定有关/需要查看它的一个示例。
在我忘记之前,我的<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
也在我的app.config
的system.serviceModel
之内。
可能重复[HttpContext.Current.Server null](http://stackoverflow.com/questions/6304532/httpcontext-current-server-null) –
Web vs Wcf?我不认为这是重复的@JeffBridgman – Matt