Windows Peer Near Me(PNM)API在Windows 10中不起作用?

时间:2015-11-02 13:14:24

标签: .net windows-10 p2p pnrp

我们尝试使用.Net代码使用Windows PNM API,使用以下示例代码:

using System;
using System.Net.PeerToPeer;
using System.Net.PeerToPeer.Collaboration;

namespace GetPeersNearMe
{
    class Program
    {
        static void Main(string[] args)
        {            
            PeerCollaboration.SignIn(PeerScope.All);

            PeerNearMeCollection peers = null;
            try
            {
                peers = PeerCollaboration.GetPeersNearMe();
                if (peers == null ||
                    peers.Count == 0)
                {
                    Console.WriteLine("There are no peers near me.");
                }
                foreach (PeerNearMe pnm in peers)
                {
                    Console.WriteLine("Getting the peers near me: {0}, nickname {1}, isOnline {2}",
                        pnm.ToString(),
                        pnm.Nickname,
                        pnm.IsOnline);
                }
            }
            catch (PeerToPeerException p2pEx)
            {
                Console.WriteLine("Could not obtain an enumeration of the peers near me: {0}", p2pEx.Message);
            }
            catch (InvalidOperationException ioEx)
            {
                Console.WriteLine("The application is no longer signed into the Peer Collaboration Infrastructure: {0}",
                    ioEx.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unexpected exception caught when trying to enumerate the peers near me: {0}",
                    ex.Message);
            }

        }
    }

我们继续得到以下异常:

System.Net.PeerToPeer.PeerToPeerException was unhandled
  HResult=-2146233088
  Message=Peer collaboration startup failed.
  Source=System.Net
  StackTrace:
       at System.Net.PeerToPeer.Collaboration.CollaborationHelperFunctions.Initialize()
       at System.Net.PeerToPeer.Collaboration.PeerCollaboration.SignIn(PeerScope peerScope)
       at GetPeersNearMe.Program.Main(String[] args) in c:\Program.cs:line 11
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.ComponentModel.Win32Exception
       HResult=-2147467259
       Message=The Windows Peer-to-Peer infrastructure is not licensed to operate on this platform.
       ErrorCode=-2147467259
       NativeErrorCode=-2140995580
       InnerException:

我们确保在测试代码之前运行以下Windows服务:

  • 同行名称解析协议
  • 同行网络分组
  • Peer Networking Identity Manager
  • PNRP机器名称发布服务

我们仍然得到上述异常。我们缺少什么?

我们在Windows 10计算机上运行代码,代码正在运行.Net 4.5.1

0 个答案:

没有答案