Wednesday, 21 August 2013

How to make asynchronous calls from a WCF client to WCF Service in parallel

How to make asynchronous calls from a WCF client to WCF Service in parallel

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.

No comments:

Post a Comment