Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrong SPContext in Wcf Service

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.

What am I doing wrong? How can I get right context?

like image 922
Grant Avatar asked Nov 13 '22 19:11

Grant


1 Answers

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?

like image 126
Michael Stum Avatar answered Jan 05 '23 21:01

Michael Stum