开发者

Wrong SPContext in Wcf Service

开发者 https://www.devze.com 2023-03-22 02:07 出处:网络
I have SharePoint 2010 (_http://sp2010/, for instance). I have created site (_http://sp2010/site/) and WCF Service, which is hosted in ISAPI folder. In service I have such test method:

I have SharePoint 2010 (_http://sp2010/, for instance). I have created site (_http://sp2010/site/) and WCF Service, which is hosted in ISAPI folder. In service I have such test method:

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

I call service from my console application using this address - _http://sp2010/site/_vti_bin/WcfService.svc/mex. When calling method GetCurrentWebUrl I expect to get _http://sp2010/site/, but I always get _http://sp2010/. In other words SPContext is not correct.

开发者_如何学CWhat am I doing wrong? How can I get right context?


Can you double check that you are really calling http://sp2010/site/_vti_bin/WcfService.svc/mex? When using the Visual Studio Add Service Reference dialog, it usually uses the root, as in http://sp2010/_vti_bin/WcfService.svc/mex.

If you are setting it up in code it should indeed work, at least it does for me :(

What is SPContext.Current.Web.Url and Web.ID? Does that match the /site/ Web?

0

精彩评论

暂无评论...
验证码 换一张
取 消