5

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?

Grant
  • 2,295
  • 3
  • 14
  • 13

1 Answers1

1

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?

Michael Stum
  • 177,530
  • 117
  • 400
  • 535
  • That's the point, `SPContext.Current.Web.Url = http://sp2010/`. I have another site: `http://sp2010/site2/`. I tried with this one, but again `SPContext.Current.Web.Url = http://sp2010/` – Grant Jul 24 '11 at 09:01
  • @Grant and you are 100% sure that you are hitting _vti_bin in the correct sub-site and not on the root? Use fiddler to verify that you are indeed hitting the URL you want to hit: http://www.fiddler2.com/fiddler2/ – Michael Stum Jul 24 '11 at 09:03
  • I'm pretty sure, but I'll check it with fiddler. Thanks for advice! – Grant Jul 24 '11 at 09:05
  • I've checked, URL is correct. You know what I mentioned - even when I call this service within site that does not exist (for example, `http://sp2010/somesite/_vti_bin/WcfService.svc`), I get response without any error and `SPContext.Current.Web.Url` again is `http://sp2010/`. – Grant Jul 25 '11 at 06:22