views:

59

answers:

3

I'm trying to learn WCF to use it as an IPC mechanism for a host/plugin system. The host needs to be able to call the plugin to Start/Stop it, and the plugin needs to call the server back to perform logging.

I made a simple test case where the host creates an endpoint on "net.pipe://localhost/SampleServer" with the following ServiceContract:

[ServiceContract]
public interface IWcfServer
{
    [OperationContract]
    void Log(string message);
}

And the plugin creates an endpoint on "net.pipe://localhost/SampleClient" with the following ServiceContract:

[ServiceContract]
public interface IWcfClient
{
    [OperationContract]
    string Init();
}

Here's a sample of how I'm setting up each endpoint:

this.server = new ServiceHost(this);
this.server.AddServiceEndpoint(typeof(IWcfServer), new NetNamedPipeBinding(), "net.pipe://localhost/SampleServer");
this.server.Open();

And here's a sample of how I'm making the calls:

ChannelFactory<IWcfClient> factory = new ChannelFactory<IWcfClient>(new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/SampleClient"));
IWcfClient client = factory.CreateChannel();
using ((IClientChannel)client)
{
    client.Init());
}

I already confirmed that the host can call plugin.Init(), and the plugin can call host.Log(message) without issues. However, if this following scenario happens:

  1. Host calls plugin.Init()
  2. During the execution of plugin.Init(), the plugin attempts to call host.Log(message)

The applications freezes, and I get a TimeoutException after 1min. Anyone has any ideas on what I'm be doing wrong?

A: 

1 min is the standard wcf timeout.

Do you have a circular reference?

Also, why do you have 2 contracts, when you make a call to client.init who is listening?

Shiraz Bhaiji
No circular reference, see my comment on Sajay's message. I have two contracts and two different endpoints because there's two independent communication paths between the host and the plugin. The host implements IWcfServer and makes the call to plugin.Init, while the plugin implements IWcfClient and makes the call to host.Log.
Badaro
A: 

Turn on E2E tracing for WCF to check what exactly is timing out. - http://msdn.microsoft.com/en-us/library/ms733025.aspx. Besides your methods might be causing a deadlock since init might require log and log might require init to happen first or something like that.

Sajay
I know there is no circular reference, since the current log "implementation" is simply MessageBox.Show(message). I'll enable that trace and take a look at it tomorrow.
Badaro
A: 

what is the InstanceContextMode of the service host ? If it is a singleton, it will block until Init() returns - resulting in a circular dependency.

TSV
It is. I found out that for that particular sample it would work if I added UseSynchronizationContext=false, but for the real application I ended up rewriting things to use InstanceContextMode.PerCall.
Badaro