简体   繁体   中英

WCF deadlock when calling service from two separate clients

I have a WCF service(hosted in a WPF application) that handles the communication between clients(WPF). There's a scenario, where one client sends a message to the servuce, who broadcasts it to the other clients but the message results in the other client sending a new message back and they all freeze. After some reading I suspect that the second client tries to make a call to the service while the service's call still hasn't finished (using the same channel). However, I'm not sure is my assumption correct and if so how to overcome it.

In a bit more detail: the clients are text editors. If you write in one, operations that represent the changes are sent to the service and from there to the other clients. When I try to send operations about the others' caret movements though, it freezes. I assume it's because the InsertOperation that the second client receives causes a caret movement and it tries to send a CaretMoveOperation back in the event handler making a call using the same channel the service uses for sending the message, causing a deadlock.

What do you think? Can you suggest something?

I would check two things

  1. is the CPU levels on your app spiking when you invoke the call? Are you getting an infinite loop that is giving the appearance of a lock?
    1. Are you using synchronous messages that wait for termination? because then you will get into a loop. Make sure you aren't calling back on the same thread with a synchronous operation. You should use an asynch messaging design, possibly on separate tasks from your event handler

You have to look at your service behavior attribute. When things look like only one message is processed at a time (it probably means single threaded).

An excerpt from MSDN


The ConcurrencyMode property interacts with some other settings. For example, if the InstanceContextMode value is set to Single the result is that your service can only process one message at a time unless you also set the ConcurrencyMode value to Multiple. This property also produces behavior in combination with the ServiceContractAttribute.SessionMode property. For details, see Sessions, Instancing, and Concurrency.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM