Web service not handling multiple simultaneous request from same application with proxy class

大城市里の小女人 提交于 2020-01-13 19:10:48

问题


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.ProxyClassService();
                    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


回答1:


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?



来源:https://stackoverflow.com/questions/5990469/web-service-not-handling-multiple-simultaneous-request-from-same-application-wit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!