我正在尝试学习 WCF 以将其用作主机/插件系统的 IPC 机制。主机需要能够调用插件来启动/停止它,插件需要回调服务器来执行日志记录。
我做了一个简单的测试用例,主机net.pipe://localhost/SampleServer
使用以下 ServiceContract 创建端点:
[ServiceContract]
public interface IWcfServer
{
[OperationContract]
void Log(string message);
}
net.pipe://localhost/SampleClient
该插件使用以下 ServiceContract创建一个端点:
[ServiceContract]
public interface IWcfClient
{
[OperationContract]
string Init();
}
这是我如何设置每个端点的示例:
this.server = new ServiceHost(this);
this.server.AddServiceEndpoint(typeof(IWcfServer),
new NetNamedPipeBinding(),
"net.pipe://localhost/SampleServer");
this.server.Open();
这是我如何拨打电话的示例:
ChannelFactory<IWcfClient> factory = new ChannelFactory<IWcfClient>(
new NetNamedPipeBinding(),
new EndpointAddress("net.pipe://localhost/SampleClient"));
IWcfClient client = factory.CreateChannel();
using ((IClientChannel)client)
{
client.Init());
}
我已经确认主机可以调用plugin.Init()
,插件可以正常调用host.Log(message)
。但是,如果发生以下情况:
- 主机调用 plugin.Init()
- 在 plugin.Init() 执行期间,插件尝试调用 host.Log(message)
应用程序冻结,我TimeoutException
在 1 分钟后得到一个。有人对我做错了什么有任何想法吗?