在尝试HostingEnvironment.MapPath()使用我的 WCF 应用程序时遇到一些问题。
我创建了一个带有静态方法的类来检查是否HttpContext.Current为空:
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")and Server.PathPath("./file.xml"))。如果有人想知道为什么我有“字符串结果”;这是因为我添加if (string.IsNullOrEmpty(result))并添加了result = Directory.GetCurrentDirectory() + path;
在使用 WCF 测试客户端进行测试时,是否有其他人遇到过这样的问题?
请让我知道这是否与绑定/需要查看它的示例有关。
在我忘记之前,我也有我<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>的。system.serviceModelapp.config