Why are my message be processed out of order over a single WCF TCP channel (with ConcurrencyMode.Reentrant)?

后端 未结 3 614
猫巷女王i
猫巷女王i 2021-01-05 22:45

The client sends a lot of messages to the server from a single thread, over a single WCF channel.

The client sends the message with BeginMyMethod(x, b) as it does

相关标签:
3条回答
  • 2021-01-05 23:06

    I have now worked round this problem by:

    • Changing all my call-backs from the server to the client to be OneWay
    • Using a dispatcher in the client before passing on any callback from the server, so client code never calls the sever from within a call-back
      • The client call-back object is marked with CallbackBehavior(UseSynchronizationContext=false, ConcurrencyMode=ConcurrencyMode.Single)
      • When running in Winform or WPF I use SynchronizationContext.Post to depatch the callbacks
      • When the cleint is a Console or a Windows server I use a custom depatcher.
    • So letting me use ConcurrencyMode.Single on both the server and the client.

    It is now working as expected.
    (BeginMyMethod(x, b) is still being used to send messaged from the client to the server)

    (ConcurrencyMode.Reentrant seems to sometimes release the lock even when the WCF call is not made on the some thread that is processing the incoming message, it is just not a useful as Reentrant was in DCOM)

    0 讨论(0)
  • 2021-01-05 23:13

    If you are using the generated BeginXXX async-methods, these are executed on a ThreadPool thread. So although you've send the messages in a defined order, nobody guarantees you in which order the ThreadPool executes the requests.

    0 讨论(0)
  • 2021-01-05 23:15

    I think that Reentrant mode implies that you allow messages be processed out of order. Normal behavior of such service would be: get message, put in queue for internal threads to process, and when it's done notify client about result. So maybe your service get messages in proper order but some of them are quiker to process and return earlier than others?

    0 讨论(0)
提交回复
热议问题