I have a WCF service that I use to replace the old ASP.NET web service. The service is working fine, but for some reason, it cannot handle concurrent requests. My service implementation has the following properties:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Multiple)] public class HHService : IHHService
My host declaration is as follows:
baseAddress = new Uri("http://0.0.0.0:8888/HandHeld/"); host = new ServiceHost(typeof(HHService), baseAddress); ServiceMetadataBehavior behavior; behavior = host.Description.Behaviors.Find<ServiceMetadataBehavior>(); if (behavior == null) { behavior = new ServiceMetadataBehavior(); behavior.HttpGetEnabled = true; behavior.MetadataExporter.PolicyVersion = PolicyVersion.Policy15; host.Description.Behaviors.Add(behavior); } host.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,MetadataExchangeBindings.CreateMexHttpBinding(), "mex"); host.AddServiceEndpoint(typeof(IHHService), new BasicHttpBinding(), "HHService.asmx"); HHService.LogMessage += new EventHandler<HHService.LogMessageEventArgs>(HHService_LogMessage); host.Open();
The service starts and returns the correct results, but if two clients try to make a call at the same time, one client will be blocked until the other is completed, and not calls made together. I do not use configuration files. I am trying to do everything programmatically. I have something incorrectly configured, what causes this behavior? I am starting other services using NetTCPBinding without this problem.
EDIT: In response John Saunders: I am not familiar with any ASP.NET compatibility mode. I do not use any session state that the service has no status, it just processes the requests. Besides the implementation of real methods, everything else I have done is in the code indicated here.
Possible Solution:
I called the host.Open() function from the form_load event of the main form. I transferred the call to a separate thread. All this thread was called by host.Open() , but now the service seems to behave as I expected.
source share