0

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: webservice oneway and new SPSite(myUrl)


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;
Community
  • 1
  • 1
dirq
  • 968
  • 2
  • 11
  • 26
  • So, we just took off the oneway attribute and are just calling it synchronously. Site creation doesn't seem to time out at this point but we'd ideally like to call it asynchronously since we still have things to add that will make it run even longer. Any ideas or best practices on kicking off long-running jobs in the OnActivated event of a Windows Sharepoing Services site definition? Are web services the way to go or should I research the timer jobs or kicking off another thread? – dirq Apr 24 '09 at 13:51
  • Note: When calling a web service with the OneWay attribute you do not have access to the HttpContext using the static Current property (HttpContext.Current). To access the HttpContext, derive the class implementing the XML Web service method from WebService and access the Context property (this.Context) instead. One-way methods cannot have a return value or any out parameters. – dirq Apr 24 '09 at 13:55

1 Answers1

0

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
  • 10,630
  • 28
  • 36