本文介绍了WCF对等,是否有结点在那里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用WCF的.NET 3.5实现点对点组网应用。要解决我使用PNRP对等节点。

IGlobalStoreServiceContract是我的合同,如下图所示,

  [的ServiceContract(命名空间=HTTP://GlobalStoreEventDriven.API​​,CallbackContract = typeof运算(IGlobalStoreServiceContract))]
内部接口IGlobalStoreServiceContract
{
    [OperationContract的(IsOneWay =真)
    无效NotifyGlobalStoreDataInserted(字符串globalGroup,日期时间maxDateTime);

    [OperationContract的(IsOneWay =真)
    无效RegisterNode();

    [OperationContract的(IsOneWay =真)
    无效SynchronizeMemberList(GUID ClientID的);
}
 

我使用了一些code这样的加盟每个节点的对等网络。

  DuplexChannelFactory< IGlobalStoreChannel>的ChannelFactory =新DuplexChannelFactory< IGlobalStoreChannel>(例如,GlobalStoreAPIEndPoint);
IGlobalStoreChannel globalStoreChannel = channelFactory.CreateChannel();

globalStoreChannel.Open();
 

我的问题,只要我打开了通道我如何能最好地判断其它对等节点在网络上是?

比如我可以打电话给在我的合同RegisterNode的方法之一,而网络中的每个节点可以使用回调来调用SynchronizeMemberList。然后我会知道的其它节点是否在那里。

与麻烦的是它是所有异步的。如果我打电话RegisterNode,没有人回答,它并不真正意味着没有一个人,它可能只是意味着我没有等到足够长的时间。

你怎么算?有什么建议?

解决方案

请参阅同行点对点编程与WCF和.NET Framework 3.5:对等名称通过阿米特Bahree和克里斯·佩里斯:

  PeerName MyPeer的=新PeerName(MySecurePeer,PeerNameType.Secured);
PeerNameResolver解析器=新PeerNameResolver();

PeerNameRecordCollection结果= resolver.Resolve(MyPeer的);

Console.WriteLine({0}同行实测值:,results.Count.ToString());
INT I = 1;

的foreach(PeerNameRecord同行中的结果)
{
    Console.WriteLine({0}同伴:{1},我++,peer.PeerName.ToString());
    的foreach(IPEndPoint知识产权peer.EndPointCollection)
    {
        Console.WriteLine(\ t端点:{0},ip.ToString());
    }
}
 

所以,我想你应该看看<$c$c>PeerNameResolver.Resolve方法:

I am using WCF in .NET 3.5 to implement a peer to peer networking application. To resolve peer nodes I am using PNRP.

IGlobalStoreServiceContract is my contract as shown below,

[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);
}

I am using some code like this to join each node to the peer to peer network.

DuplexChannelFactory<IGlobalStoreChannel> channelFactory = new DuplexChannelFactory<IGlobalStoreChannel>(instance, "GlobalStoreAPIEndPoint");
IGlobalStoreChannel globalStoreChannel = channelFactory.CreateChannel();

globalStoreChannel.Open();

My question is as soon as I have opened the channel how can I best tell if other peer nodes are on the network?

For instance I could call one of the methods in my contract RegisterNode, and each node in the network could use a callback to call SynchronizeMemberList. I would then know whether other nodes were there.

The trouble with that is it is all asynchronous. If I call RegisterNode and no one replies, it doesn't really mean no one is there, it could just mean that I didn't wait long enough.

What do you reckon? Any suggestions?

解决方案

See Peer-to-Peer Programming with WCF and .NET Framework 3.5: Peer Name by Amit Bahree and Chris Peiris:

PeerName myPeer = new PeerName("MySecurePeer", PeerNameType.Secured);
PeerNameResolver resolver = new PeerNameResolver();

PeerNameRecordCollection results = resolver.Resolve(myPeer);

Console.WriteLine("{0} Peers Found:", results.Count.ToString());
int i = 1;

foreach (PeerNameRecord peer in results)
{
    Console.WriteLine("{0} Peer:{1}", i++, peer.PeerName.ToString());
    foreach (IPEndPoint ip in peer.EndPointCollection)
    {
        Console.WriteLine("\t Endpoint: {0}", ip.ToString());
    }
}

So, I guess you should check out PeerNameResolver.Resolve Method:

这篇关于WCF对等,是否有结点在那里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 12:21