Click here to Skip to main content
Sign Up to vote bad
good
See more: WCF
I was reading an article by Juval Lowy. Below section is not clear to me.My Question is : Why callback re requires the ownership of lock? I mean the thread in which the call back is called is waiting for callback to return.so this thread should resume after the callback returns, just like any other method call.
 
The service may also want to invoke the callback reference passed in or invoke the list of callbacks during the execution of a contract operation. However, such invocations are disallowed because by default the service class is configured for single-threaded access: the service instance is associated with a lock, and only one thread at a time can own the lock and access the service instance. Calling out to the clients during an operation requires blocking the service thread while invoking the callbacks. The problem is that processing the reply message from the client once the callback returns requires ownership of the same lock, and so a deadlock would occur.
To avoid a deadlock, if the single-threaded service instance tries to call back to its clients, Windows Communication Foundation will throw an InvalidOperationException
Posted 9 Sep '12 - 21:09
Edited 10 Sep '12 - 11:03
Wes Aday59.2K

Comments
Sergey Alexandrovich Kryukov - 10 Sep '12 - 16:35
Do you think it's OK to ask a question on an article without a reference?! I think it's not nice at all. --SA

2 solutions

In general case, a callback does not require ownership of a lock, but it can be required if the callback has access to some shared objects. That's it.
For the concrete detail, please address to Juval Lowy. I did not read the article, because you did not give me a reference.
 
Best regards,
—SA
  Permalink  
Comments
Espen Harlinn - 10 Sep '12 - 18:00
5'ed!
Sergey Alexandrovich Kryukov - 10 Sep '12 - 21:27
Thank you, Espen. --SA
I assume you are referring to this article What You Need To Know About One-Way Calls, Callbacks, And Events[^]. The real goodie in that article is under the heading "Queued Publishers and Subscribers" which describes how to use WCF with MSMQ, enabling true asychronous operation.
 
Have a look at WCF / WPF Chat Application[^], it's a better example.
 
Best regards
Espen Harlinn
  Permalink  
Comments
Sergey Alexandrovich Kryukov - 10 Sep '12 - 21:29
Well, that should provide an overview of what's involved. Considering the lack of information provided by OP, it would be hard to give a better answer. My 5. --SA
Espen Harlinn - 11 Sep '12 - 8:54
Thank you, Sergey :-D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 294
1 OriginalGriff 195
2 CPallini 163
3 Mahesh Bailwal 159
4 Tadit Dash 148
0 Sergey Alexandrovich Kryukov 10,169
1 OriginalGriff 7,749
2 CPallini 4,181
3 Rohan Leuva 3,482
4 Maciej Los 3,089


Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 10 Sep 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid