views:

726

answers:

6

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.

(Interestingly, 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.

A: 

Could you supply some more info and perhaps code samples?

Which specific object in SPContext.Current is null?

How do you obtain credentials for the web service?

what authentication are you using?

Anders Rask
SPContext.Current is null.
Ariel
+hosting IIS site is Windows authN. (How can this be related to SPContext.Current being null?)
Ariel
A: 

Also, where is it being called from?

zincorp
Not sure how that makes a difference, but anyway, it's being called from a web part running on that same web app.
Ariel
A: 

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

jlew
http: //server is a valid web application.
Ariel
The question really was if "subdir" is also an application, which would supercede the parent directory's application and provide a different context in which SP is not running. You could determine this by inspecting the properties of "System.Web.Hosting.HostingEnvironment" in the debugger.
jlew
A: 
Paul-Jan
Will give a try... as you mention, everything is hosted under ISAPI dir, code lives in a GAC'ed dll, etc. Web service actually works. Thanks.
Ariel
Note: you also get SPContext.Current = null if code is called within service such as OWSTIMER (timer job).
Janis Veinbergs
A: 

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
{
    ...
    ...
}
David
Yes it is, and yes, I added the ScriptService attrib, but I'm not sure how that can be related in any case. Thanks.
Ariel
A: 

Hi,

Did you get any answer to this? I have the same problem, I placed the asmx either in the layouts and isapi folders and i'm still getting spcontext.current = null...

Nicolas Ibarra Salazar