【发布时间】:2009-07-08 10:33:14
【问题描述】:
我在 .NET 3.5 中使用 WCF 来实现对等网络应用程序。为了解析对等节点,我使用 PNRP。
IGlobalStoreServiceContract 是我的合约如下图,
[ServiceContract(Namespace = "http://GlobalStoreEventDriven.API", CallbackContract = typeof(IGlobalStoreServiceContract))]
internal interface IGlobalStoreServiceContract
{
[OperationContract(IsOneWay = true)]
void NotifyGlobalStoreDataInserted(string globalGroup, DateTime maxDateTime);
[OperationContract(IsOneWay = true)]
void RegisterNode();
[OperationContract(IsOneWay = true)]
void SynchronizeMemberList(Guid clientId);
}
我正在使用类似这样的代码将每个节点加入对等网络。
DuplexChannelFactory<IGlobalStoreChannel> channelFactory = new DuplexChannelFactory<IGlobalStoreChannel>(instance, "GlobalStoreAPIEndPoint");
IGlobalStoreChannel globalStoreChannel = channelFactory.CreateChannel();
globalStoreChannel.Open();
我的问题是,一旦我打开了通道,如何才能最好地判断其他对等节点是否在网络上?
例如,我可以调用我的合约 RegisterNode 中的一种方法,并且网络中的每个节点都可以使用回调来调用 SynchronizeMemberList。然后我会知道是否还有其他节点。
问题在于它都是异步的。如果我调用 RegisterNode 并且没有人回复,这并不意味着真的没有人在那里,它可能只是意味着我没有等待足够长的时间。
你怎么看?有什么建议吗?
【问题讨论】: