Question

I’m writing a service that has a call that is relatively long running. The client needs to be able to make successive requests that run in parallel to each other and for some reason my service will not execute them concurrently unless the calls are executed from separate clients. I'm trying to figure out what configuration setting(s) I'm missing.

I’m using the netTcpBinding. My throttling configuration is:

<serviceThrottling maxConcurrentInstances="10" maxConcurrentCalls="10" maxConcurrentSessions="10"/>

The service contract:

[ServiceContract(CallbackContract=typeof(ICustomerServiceCallback))]
    public interface ICustomerService
    {
[OperationContract(IsOneWay = true)]
        void PrintCustomerHistory(string[] accountNumbers, 
            string destinationPath);
}

[ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall)]
    public class CustomerService : ICustomerService
    {

public void PrintCustomerHistory(string[] accountNumbers, 
            string destinationPath)
        {
//Do Stuff..
}
}

In the client, I’m making two successive asynchronous calls:

openProxy();

//call 1)
                proxy.PrintCustomerHistory(customerListOne, @"c:\DestinationOne\");

//call 2)
                proxy.PrintCustomerHistory(customerListTwo, @"c:\DestinationTwo\");

On the service, the second operation begins only after the first one ends. However, if I execute both calls from separate clients, they both execute concurrently by the service.

What am I missing? I had assumed that by marking my service class as “PerCall” that call 1 and call 2 each would receive their own InstanceContext and therefore execute concurrently on separate threads.

Was it helpful?

Solution

You need to make the client calls asynchronous. If you're using VS 2012, you can enable the Task based asynchronous calls in the service reference, then call via:

var task1 = proxy.PrintCustomerHistoryAsync(customerListOne, @"c:\DestinationOne\");
var task2 = proxy.PrintCustomerHistoryAsync(customerListTwo, @"c:\DestinationTwo\");

// The two tasks are running, if you need to wait until they're done:
await Task.WhenAll(task1, task2);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top