5

我有 SharePoint 2010(例如 _http://sp2010/)。我创建了站点 (_http://sp2010/site/) 和 WCF 服务,它们托管在 ISAPI 文件夹中。在服务中我有这样的测试方法:

[OperationContract]
public string GetCurrentWebUrl()
{
    return SPContext.Current.Site.Url + " | " + SPContext.Current.Web.Url;
}

我使用此地址从我的控制台应用程序调用服务 - _http://sp2010/site/_vti_bin/WcfService.svc/mex。当调用 GetCurrentWebUrl 方法时,我希望得到 _http://sp2010/site/,但我总是得到 _http://sp2010/。换句话说 SPContext 是不正确的。

我究竟做错了什么?我怎样才能获得正确的上下文?

4

1 回答 1

1

你能仔细检查一下你真的在打电话http://sp2010/site/_vti_bin/WcfService.svc/mex吗?使用 Visual Studio 添加服务引用对话框时,它通常使用根目录,如http://sp2010/_vti_bin/WcfService.svc/mex.

如果您在代码中设置它确实应该可以工作,至少它对我有用:(

什么是SPContext.Current.Web.UrlWeb.ID?这与 /site/ Web 匹配吗?

于 2011-07-22T16:00:41.360 回答