views:

421

answers:

1

More specifically - How do I reference SPContext in Web Service with [SoapDocumentMethod(OneWay=true)]?

We are creating a feature that needs to run a job when a site is created. The job takes about 4 minutes to complete. So, we made a web service that we can call when the feature is activated. This works but we want it to run asynchronously now. We've found the SoapDocumentMethod's OneWay property and that would work awesomely but the SPContext is now NULL.

We have our web services in the _vti_bin virtual directory so it's available in each Windows Sharepoint Services site. I was using the SPContext.Current.Web to get the site and perform the long running operation. I wanted to just fire and forget about it by returning a soap response right away and letting the process run.

How can I get the current SPContext? I used to be able to do this in my web service:

SPWeb mySite = SPContext.Current.Web;

Can I get the same context when I have the [SoapDocumentMethod(OneWay=true)] attribute applied to my web service?

Or must I recreate the SPWeb from the url?

This is similar to this thread: http://stackoverflow.com/questions/340192/webservice-oneway-and-new-spsitemyurl


Update: I've tried these two ways but they didn't work:

SPWeb targetSite = SPControl.GetContextWeb(this.Context);

SPWeb targetSite2 = SPContext.GetContext(this.Context).Web;
A: 

One-way methods cannot have a return value or any out parameters

But they do have in parameters don;t they?

When you do the call to the webservice method, can't you pass in the url of the current site from the featurereceiver and then do using(SPSite site = new SPSite(urlPassedAsParameter)) in the web service method?

The SPFeatureReceiverProperties in the FeatureActivated override has the current SPWeb or SPSite as SPFeatureReceiverProperties.Parent.

Colin