Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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:09pm
Edited 10-Sep-12 11:03am
Wes Aday61.2K
v2
Comments
Sergey Alexandrovich Kryukov at 10-Sep-12 16:35pm
   
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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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 at 10-Sep-12 18:00pm
   
5'ed!
Sergey Alexandrovich Kryukov at 10-Sep-12 21:27pm
   
Thank you, Espen. --SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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 at 10-Sep-12 21:29pm
   
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 at 11-Sep-12 8:54am
   
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 685
1 Manas Bhardwaj 380
2 OriginalGriff 344
3 Abhinav S 293
4 Sampath Lokuge 245
0 Sergey Alexandrovich Kryukov 7,967
1 OriginalGriff 4,332
2 Peter Leow 3,699
3 Maciej Los 3,515
4 Er. Puneet Goel 3,107


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