Call long running operation in WSS feature OnActivated Event

*爱你&永不变心* 提交于 2019-12-13 04:11:10

问题


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;

回答1:


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.



来源:https://stackoverflow.com/questions/781944/call-long-running-operation-in-wss-feature-onactivated-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!