Monday, September 14, 2009

Custom web service - 401 Unauthorized

So I remember what I did for next time...

I have a custom web service that interacts with SharePoint. I created a new method so I could test the service from a Windows Form application - invokes a method without any parameters, then returns an item from a SharePoint list. Simple enough.

Of course, never say "simple enough"! In my code I could get a handle to the SPSite object, and the SPWeb object, but when I tried to get an SPList object or do an rootweb.Lists.Count property check I'd get a "thread was being aborted" message, and a 401 Unauthorized back. I increased the timeout in my proxy class, increased the HttpRuntime timeout, all no luck.

But then in my web service ASMX class, I added in SPSecurity.RunWithElevatedPrivileges - and poof the web service now works.

No comments: