Why is my Winforms single-stream WCF services?

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.

+4
source share
4 answers

If your context mode is a PerCall instance, your server is always single-threaded, because by definition each call receives a new server instance.

This works well in an IIS environment where IIS can deploy multiple server instances to handle n simultaneous callers, each of which is a single-threaded server for each incoming request.

You mention in one of your comments your hosting of your WCF inside the forms application - this may be a design decision that you need to reconsider - this is not entirely optimal, since the Winforms application cannot easily process multiple subscribers and deploy multiple instances of a service code.

Mark

+4
source

Is there any lock in your service function?

0
source

Are you using ASP.NET compatibility mode? Session state?


My next question is: what makes you think it's single-threaded? How did you determine this and what test do you use to prove that you did not solve the problem? May be false.

0
source

Another question answers this:

 [ServiceBehavior(UseSynchronizationContext = false)] 

WCF in Winforms application - is it always single-threaded?

0
source

Source: https://habr.com/ru/post/1286349/


All Articles