开发者

SPContext.Current is null in a web service under a sharepoint site

开发者 https://www.devze.com 2022-12-20 06:30 出处:网络
I\'m exposing a web service in a SharePoint site e.g. http://server/_vti_bin/subdir/mywebservice.asmx.

I'm exposing a web service in a SharePoint site e.g. http://server/_vti_bin/subdir/mywebservice.asmx.

In the web service method, SPContext.Current appears to be null.

(Interest开发者_运维问答ingly, I'm looking at an example in Chapter 5 of Inside Windows SharePoint Services 3.0 and they use SPContext.Current inside a web service!)

Any idea what am I missing? Thanks in advance.


The only times when I saw a SPContext.Current = null was when the webservice was called at a virtual location that didn't exist (i.e. an URL that was only half correct).

In your problem specification, you mention "_vti_bin/subdir". I have not seen this subdir construct in a WebService hosted within SharePoint yet (disclaimer: my knowledge is limited to 2 or 3 working implementations of a custom webservices within SharePoint)

Normally, you'd

  • Put the asmx straight into the ISAPI folder of the 12 hive. This will map onto _vti_bin.
  • Put the assembly, if any, in the GAC (or in the website bin, but I'd suggest using the GAC until you get the basics up and running)
  • Do stuff for discovery if you really need to, but for testing this shouldn't be necessary

It might not be related at all, but I'd still try to get things working from the _vti_bin first, then try and mess with subfolders. SharePoint's url virtualization can be painful.


Is it possible that your subdirectory is set up as a web application and is therefore operating in a different context?


How are you calling the webservice? Is this an ajax call from javascript/jquery? If yes, have you added the ScriptService attribute on the webservice class?

[System.Web.Scripts.Services.ScriptService]
public class SimpleWebService : System.Web.Services.WebService
{
    ...
    ...
}
0

精彩评论

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

关注公众号