简体   繁体   English

多个WCF请求的最佳方法

[英]Best approach for multiple WCF requests

I have a method that receives an array of productIds and with them i need to get a date for each one. 我有一个方法接收一个productIds数组,并与他们我需要得到每个的日期。 The thing is that the service is only able to give me a date for each product. 问题是该服务只能给我一个每个产品的日期。 I have no access to service side... only client. 我无法访问服务端...只有客户端。 Is there a better way to do the code bellow? 是否有更好的方法来执行下面的代码?

ChannelFactory<IService> channelFactory = null;
IService client = null;
List<DateTime> dates = new List<DateTime>();

using (channelFactory = new ChannelFactory<IService>("endpointName"))
{
    for (int i = 0; i < productIds.Length; i++)
    {
        client = channelFactory.CreateChannel();

        Request request = new Request();
        request.Id = productIds[i];

        Response response = client.execute(request);
        dates.Add(response.Date);
    }
}

Looks like you don't have to create channel on each iteration, just once before the loop. 看起来您不必在每次迭代时创建通道,只需在循环之前创建一次。 You can also try to parallelize the flow: svcutil can generate task-based async operations, I believe that there is something like that in ChannelFactory itself as well. 您也可以尝试并行化流程:svcutil可以生成基于任务的异步操作,我相信在ChannelFactory本身也有类似的东西。 But I'm afraid it's not possible to reduce amount of service calls without proper server-side support. 但是,如果没有适当的服务器端支持,我担心不可能减少服务呼叫量。

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

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