简体   繁体   English

多线程Web服务调用asp.net Web表单

[英]Multithreaded web service calls in asp.net web forms

I have an aspx page to make calls to a web service, each of which can take up to few minutes and I want to make it work in a multi-threaded way. 我有一个aspx页面来调用Web服务,每个页面都需要几分钟,我想让它以多线程方式工作。 Basically what I want is when user clicks one of the buttons I want to make a service call to my web service but I also want user to be able to click the other buttons and make other service calls if they want. 基本上我想要的是当用户点击我想要对我的网络服务进行服务调用的其中一个按钮时,我还希望用户能够点击其他按钮并根据需要进行其他服务调用。 and if the later calls are completed faster than the first one, results must be shown to user without waiting for the result of the first call. 如果后续调用的完成速度比第一次快,则必须向用户显示结果,而不等待第一次调用的结果。 (Yo can think about desktop sql editor applications) (哟可以考虑桌面sql编辑器应用程序)

However I can't manage this with my current method. 但是我无法使用当前的方法来管理它。 The first call always blocks the following ones, I wonder If I can accomplish this kind of behviour in a web application. 第一个调用总是阻止以下的调用,我想知道如果我能在Web应用程序中完成这种行为。

I use a code like the floowing for my service calls: 我使用像floowing这样的代码来进行服务调用:

protected void GetResult_Click(object sender, EventArgs e)
{
   ShowSelectData(sql, connStr, tabId);
}

private void ShowSelectData(string sql, string connStr, string tabId)
{
    SqlServiceClient cli = new SqlServiceClient();
    cli.ShowSelectDataCompleted += cli_ShowSelectDataCompleted;
    cli.ShowSelectDataAsync(sql, connStr, tabId);
 }  
void cli_ShowSelectDataCompleted(object sender, SqlService.ShowSelectDataCompletedEventArgs e)
{
     var res = e.Result;
     //here I show resullts to user
}

I also add Async="true" to my aspx page 我还将Async =“true”添加到我的aspx页面

Basically what I want is when user clicks one of the buttons I want to make a service call to my web service but I also want user to be able to click the other buttons and make other service calls 基本上我想要的是当用户点击我想要对我的网络服务进行服务调用的其中一个按钮但我也希望用户能够点击其他按钮并进行其他服务调用

What you asked can be accomplished by ajax async call; 你问的问题可以通过ajax异步调用完成; leave to your client the burden to call the service (by an async call) and manage the response. 给客户留下调用服务的负担(通过异步调用)并管理响应。

When the user click a button make a call to the service; 当用户点击一个按钮拨打该服务时; meantime the first call is executing the client can call the second, meantime first and second are executing the client can call the third... the user is not frozen waiting the first call to finish 同时第一个调用是执行客户端可以调用第二个,同时第一个和第二个正在执行客户端可以调用第三个...用户没有冻结等待第一次调用完成

If you can't call the service directly from a javascript client wrap server side the service calls into rest services and call the rest services from your client. 如果您无法直接从javascript客户端包装服务器端调用该服务,则该服务将调用其他服务并从您的客户端调用其余服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM