在 WSS 功能 OnActivated 事件中调用长时间运行的操作
更具体地说 - 如何使用 [SoapDocumentMethod(OneWay=true)] 在 Web 服务中引用 SPContext?
我们正在创建一个功能,需要在创建站点时运行作业。 该作业大约需要 4 分钟才能完成。 因此,我们制作了一个 Web 服务,当该功能激活时我们可以调用该服务。 这可行,但我们希望它现在异步运行。 我们已经找到了 SoapDocumentMethod 的 OneWay 属性,这会非常有效,但 SPContext 现在为 NULL。
我们的 Web 服务位于 _vti_bin 虚拟目录中,因此每个 Windows Sharepoint Services 站点都可以使用它。 我使用 SPContext.Current.Web 来获取站点并执行长时间运行的操作。 我想通过立即返回肥皂响应并让进程运行来直接解雇并忘记它。
如何获取当前的 SPContext? 我曾经能够在我的 Web 服务中执行此操作:
SPWeb mySite = SPContext.Current.Web;
当我将 [SoapDocumentMethod(OneWay=true)] 属性应用于我的 Web 服务时,我可以获得相同的上下文吗?
或者我必须从 url 重新创建 SPWeb?
这类似于此线程:webservice oneway 和 new SPSite(myUrl)
更新:I已经尝试过这两种方法,但它们不起作用:
SPWeb targetSite = SPControl.GetContextWeb(this.Context);
SPWeb targetSite2 = SPContext.GetContext(this.Context).Web;
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;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
但它们确实有输入参数,不是吗?
当你调用webservice方法时,你不能从featurereceiver中传入当前站点的url然后执行
使用(SPSite site = new SPSite(urlPassedAsParameter))
在网络服务方法中?
FeatureActivated 替代中的 SPFeatureReceiverProperties 将当前 SPWeb 或 SPSite 作为 SPFeatureReceiverProperties.Parent。
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.