【发布时间】:2010-10-08 19:00:44
【问题描述】:
我正在尝试学习 WCF 以将其用作主机/插件系统的 IPC 机制。主机需要能够调用插件来启动/停止它,插件需要回调服务器来执行日志记录。
我做了一个简单的测试用例,主机使用以下 ServiceContract 在net.pipe://localhost/SampleServer 创建端点:
[ServiceContract]
public interface IWcfServer
{
[OperationContract]
void Log(string message);
}
插件使用以下 ServiceContract 在net.pipe://localhost/SampleClient 上创建一个端点:
[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)
应用程序冻结,1 分钟后我收到TimeoutException。有人对我做错了什么有任何想法吗?
【问题讨论】:
-
仅供参考,
void上的“IsOneWay”-返回Log()可能有助于避免阻塞[OperationContract(IsOneWay = true)]- 请参阅msdn.microsoft.com/en-us/library/…,如dotnet-experience.blogspot.com/2012/02/… 中所述
标签: wcf ipc named-pipes timeoutexception