web服务可以将回调函数作为参数吗?(can a webservice take a callback function as a parameter?)

编程入门 行业动态 更新时间:2024-10-27 00:32:07
web服务可以将回调函数作为参数吗?(can a webservice take a callback function as a parameter?)

我有一个.NET Web服务,它必须执行几个操作,我想通过回调到javascript函数显示进度。

这是功能

“//vb.NET

<WebMethod(EnableSession:=True)> _ <ScriptMethod(ResponseFormat:=ResponseFormat.Json, XMLSerializeString:=False)> _ Public Shared Function RebuildLuceneIndex(options As List(Of RebuildLuceneOption), callbackProgress As Action(Of String, Boolean)) For Each opt As RebuildLuceneOption In options Try Select Case opt.Action.ToLower() Case "clear" ....... End Select callbackProgress.Invoke(opt.Action.ToLower(), True) Catch ex As Exception callbackProgress.Invoke(opt.Action.ToLower(), False) End Try Next End Function

我正在努力研究jQuery语法来调用这个webservice传递一个json数组的字符串,并回调函数,然后我可以回调它来显示进度。

// JavaScript的

function RebuildLuceneProgressCallback(InvokedMethod, Successfull) { if (Successfull) { console.log(InvokedMethod + ' Succeeded'); } else { console.log(InvokedMethod + ' Failed'); } }

I have a .NET webservice which has to perform several actions and I would like to display progress via a callback to a javascript function.

this is the function

'//vb.NET

<WebMethod(EnableSession:=True)> _ <ScriptMethod(ResponseFormat:=ResponseFormat.Json, XMLSerializeString:=False)> _ Public Shared Function RebuildLuceneIndex(options As List(Of RebuildLuceneOption), callbackProgress As Action(Of String, Boolean)) For Each opt As RebuildLuceneOption In options Try Select Case opt.Action.ToLower() Case "clear" ....... End Select callbackProgress.Invoke(opt.Action.ToLower(), True) Catch ex As Exception callbackProgress.Invoke(opt.Action.ToLower(), False) End Try Next End Function

Im struggling to workout the jQuery syntax for calling this webservice passing a json array of strings, and a callback to the function which i can then callback into to show progress.

//javascript

function RebuildLuceneProgressCallback(InvokedMethod, Successfull) { if (Successfull) { console.log(InvokedMethod + ' Succeeded'); } else { console.log(InvokedMethod + ' Failed'); } }

最满意答案

您需要将方法拆分为两种方法:Begin&End。 请参阅有关服务器端异步Web方法的这篇文章。

然后在你的jQuery调用中,你需要调用Begin()方法,然后是后续的请求来检查方法是否已经完成。

You need to split your method up into two methods: Begin & End. See this article on Server-Side Asynchronous Web Methods.

Then in your jQuery call, you need to call the Begin() method, followed by subsequent requests to check if the method has finished.

更多推荐

本文发布于:2023-07-08 19:25:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1080008.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:回调   函数   参数   web   parameter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!