0

I have a method that receives an array of productIds and with them i need to get a date for each one. 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);
    }
}

1 Answer 1

2

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. But I'm afraid it's not possible to reduce amount of service calls without proper server-side support.

2
  • task-based async operations aren't availabel in .net 3.5 I think Apr 29, 2014 at 8:29
  • Yes, right. I missed .net-3.5 tag. I think Begin*-End* methods can do almost the same. Apr 30, 2014 at 18:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.