I have an application scheduling multiple tasks which are calling different web services, some the same web service but different method. Each task is executed in an interval and each task is running in its own thread. To obtain reference to the webservice I have a wsdl.exe generated proxy class which is instantiated inside each of the tasks and allways disposed. However when running the application, the tasks are actually waiting for eachother at the service requests, web service doesnt process the service request from task y before its done processing request from task x (I can see this because a service call from task x may take 5 minutes and task y 100 milliseconds, however if y is starting when x is running, it finishes 100 milliseconds after x is done).
This is code from a task (running inside its own thread):
public class TaskX : TaskWrapper
{
public TaskX(Guid id, string name, EventQueue eventqueue)
: base(id, name, eventqueue)
{
}
protected override void DoTask()
{
try
{
var factory = new ServiceReferenceFactory();
using (var reference = factory.GetServiceReference())
{
bool result;
bool isSpecified;
reference.Run(out result, out isSpecified);
}
}
}
}
This is the code from the factory method mentioned above:
public ProxyClassService GetServiceReference()
{
var refer = new ProxyClassServiceNamespace.ProxyCl开发者_Go百科assService();
refer.Timeout = 1000 * 60 * 60;
return refer;
}
Does anyone know why I'm experiencing this behaviour?
EDIT:
Here is some logs from tasks after I added [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)] to the implementation of my wcf service. I made none configuration changes to a wcf service created in visual studio 2008.
15:02 - Task started: TaskXWithInternalException
15:02 - Task started: TaskYQuickOne
15:02 - Task ended: TaskYQuickOne Task elapsed time: 00:00:00.1214762
15:02 - Task started: TaskZSlowOne
15:03 - Task started: TaskXWithInternalException
15:03 - Task started: TaskYQuickOne
15:05 - Task ended: TaskZSlowOne Task elapsed time: 00:03:11.6510947
15:05 - Task ended: TaskYQuickOne Task elapsed time: 00:02:09.7311905
15:06 - Task started: TaskYQuickOne
15:06 - Task ended: TaskYQuickOne Task elapsed time: 00:00:00.0546980
This is probably to do with the concurrency/instancing settings on your WCF service.
If all your calls are going to the same service instance (e.g. InstanceContextMode = PerSession or Single
), then typically you will need to make sure you have set the ConcurrencyMode
to Multiple
, otherwise the calls are serviced in a serialized fashion.
Can you tell us more about how the WCF service (not client) is setup?
精彩评论