calling a WCF service object method in another WCF service


  • Hi,

    I using two WCF services. WCF service A is hosted in my .NET Winform application and WCF Service B is hosted on a Windows Service.  Both WCF Service A and B are configured as ConcurrencyMode = ConcurrencyMode.Single and InstanceContextMode = InstanceContextMode.Single. I am using netTcpBinding.

    I am able to instantiate a client for WCF Service B and use the methods - i.e. call the WCF service hosted on Windows service from the .NET Winform app hosting WCF Service A.

    I am not able to accomplish the reverse with WCF Service A - i.e. call the WCF Service hosted on the .NET Winform application from the Windows Service hosting WCF Service B.  I am trying to make the call to WCF Service A from WCF Service B.  The call to the WCF Service A method times out.

    I have used the WCF Test client from the Visual Studio command prompt and it can successfully make calls to WCF Service A.

    What am I doing wrong from the Windows Service? Is there something I am missing?

    Please advise.

    Thanks in advance!


    Thursday, June 17, 2010 12:00 AM


All replies

  • Are you trying to call back to A from B during the outbound call to A from B - if so you will need to change the ConcurrencyMode to Reentrant
    Richard Blewett, thinktecture -
    Twitter: richardblewett
    Thursday, June 17, 2010 6:03 AM
  • No. I was actually trying to call A from B while calling B from A. I see this as two separate communications channels but, it times out.  Is this a lock issue?
    Thursday, June 17, 2010 5:41 PM
  • no its a reentrancy issue - WCF will not allow an inbound call while an outbound call is in progress on ConcurrencyMode.Single. You'll need to change to multiple and handle any thread synchronization
    Richard Blewett, thinktecture -
    Twitter: richardblewett
    Thursday, June 17, 2010 5:58 PM
  • Hello,

    as I understand your architecture you have WinForms application wich hosts WCF service A in UI thread then you have Windows service which hosts WCF service B. When you call service B from WinForms application it calls back the service A and after collection result from this call returns back to WinForms application. But your call to service A always time outs. The reason is hosting service A in UI thread. When you host WCF service in UI thread it integrates into message loop. So when you call service B the message loop waits for response from service B to complete winform event handler. When you call the service A in windows service the request is just added to a queue to be processed in the message loop => both services wait for responses = deadlock. To avoid hosting service A in UI thread, mark the service A with [ServiceBehavior(UseSynchronizationContext = false)].  

    Best regards,

    Thursday, June 17, 2010 8:20 PM
  • Thanks guys. I have solved my problem!
    Saturday, June 19, 2010 1:15 AM
  • I am facing the same problem. Could you please explain what you did to solve this?
    Wednesday, June 23, 2010 10:02 PM
  • Hello Anirban,

    if you face the same issue try to follow my last post - mark the first service class with [ServiceBehavior(UseSynchronizationContext = false)]. You can also try Richards solution - mark the first service class with [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant)] but from my experience this works with callbacks and not with separate services.

    Best regards,

    Thursday, June 24, 2010 6:30 AM