【问题标题】:WCF service need to call AsynchronousWCF服务需要调用异步
【发布时间】:2020-01-21 12:25:23
【问题描述】:

我正在尝试使用客户端异步调用 WCF 服务。 对于参考我选择生成异步操作, 问题是,如果我调用相同的服务 10 次,一旦所有 100 个服务完成,控制权就会转到完成的委托,并作为响应,它为所有 100 个服务提供相同的时间。 例如,像这样我无法获得每个呼叫的响应时间,因为所有呼叫响应都在同一时间返回。 这是我调用服务的代码

wsClient.GetCustomerGeoCodeCompleted += (sender, args) => client_GetCustomerGeoCodeCompleted(sender, args);
wsClient.GetCustomerGeoCodeAsync(GetCustomerGeoCodeRequest, lintRequestCount.ToString());

这是我的委托人

public void client_GetCustomerGeoCodeCompleted(object sender, wsIntegrationService.GetCustomerGeoCodeCompletedEventArgs e)
{
    try
    {
        if (e.Error == null)
        {
           // lintResponseCount += 1;
            WriteLog(strResponseLogpath, e.UserState + " - SUCCESS -  Get Customer Geo - " + "Record Received" + e.Result.Count().ToString()) + DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss:FFF"));

        }
        else
        {
            WriteLog(logpath, "ERROR -> : Get Customer Geo " + e.Error.Message.ToString());
        }
    }
    catch (Exception ex)
    {
        WriteLog(logpath, "ERROR -> : Get Customer Geo " + ex.Message.ToString());
    }
}

任何建议我如何在该请求的服务调用完成后尽快得到休息。

【问题讨论】:

  • 您是在客户端使用 100 个不同的实例,还是重用同一个实例?
  • 嗨@WiktorZychla 我在循环内创建实例。所以每次都会创建实例

标签: c# wcf asynchronous


【解决方案1】:

我在通话中添加了等待并根据需要工作

await Task.Run(() => wsClient.GetSalesOrderV1Async(GetSalesOrderRequest, lintRequestCount.ToString() +"-"+  dr["TenantCode"].ToString()));

如果有其他方法请告诉我

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-04
    • 2012-10-03
    • 1970-01-01
    • 2018-09-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多