public void TestClientOnLocalRpc()
        {
            Guid iid = Guid.NewGuid();
            using (RpcServerApi server = new RpcServerApi(iid))
            {
                server.AddProtocol(RpcProtseq.ncalrpc, "lrpctest", 5);
                server.AddAuthentication(RpcAuthentication.RPC_C_AUTHN_WINNT);
                server.StartListening();
                server.OnExecute +=
                    delegate(IRpcClientInfo client, byte[] arg)
                        {
                            Assert.AreEqual(0, arg.Length);
                            Assert.AreEqual(RpcAuthentication.RPC_C_AUTHN_WINNT, client.AuthenticationLevel);
                            Assert.AreEqual(RpcProtectionLevel.RPC_C_PROTECT_LEVEL_PKT_PRIVACY, client.ProtectionLevel);
                            Assert.AreEqual(RpcProtoseqType.LRPC, client.ProtocolType);
                            Assert.AreEqual(new byte[0], client.ClientAddress);
                            Assert.AreEqual(System.Diagnostics.Process.GetCurrentProcess().Id, client.ClientPid.ToInt32());
                            Assert.AreEqual(System.Security.Principal.WindowsIdentity.GetCurrent().Name, client.ClientPrincipalName);
                            Assert.AreEqual(System.Security.Principal.WindowsIdentity.GetCurrent().Name, client.ClientUser.Name);
                            Assert.AreEqual(true, client.IsClientLocal);
                            Assert.AreEqual(true, client.IsAuthenticated);
                            Assert.AreEqual(false, client.IsImpersonating);
                            using(client.Impersonate())
                                Assert.AreEqual(true, client.IsImpersonating);
                            Assert.AreEqual(false, client.IsImpersonating);
                            return arg;
                        };

                using (RpcClientApi client = new RpcClientApi(iid, RpcProtseq.ncalrpc, null, "lrpctest"))
                {
                    client.AuthenticateAs(RpcClientApi.Self);
                    client.Execute(new byte[0]);
                }
            }
        }
        public void TestPerformanceOnLocalRpc()
        {
            Guid iid = Guid.NewGuid();
            using (RpcServerApi server = new RpcServerApi(iid))
            {
                server.AddProtocol(RpcProtseq.ncalrpc, "lrpctest", 5);
                server.AddAuthentication(RpcAuthentication.RPC_C_AUTHN_WINNT);
                server.StartListening();
                server.OnExecute +=
                    delegate(IRpcClientInfo client, byte[] arg)
                    { return arg; };

                using (RpcClientApi client = new RpcClientApi(iid, RpcProtseq.ncalrpc, null, "lrpctest"))
                {
                    client.AuthenticateAs(null, RpcClientApi.Self, RpcProtectionLevel.RPC_C_PROTECT_LEVEL_PKT_PRIVACY, RpcAuthentication.RPC_C_AUTHN_WINNT);
                    client.Execute(new byte[0]);

                    byte[] bytes = new byte[512];
                    new Random().NextBytes(bytes);

                    Stopwatch timer = new Stopwatch();
                    timer.Start();

                    for (int i = 0; i < 10000; i++)
                        client.Execute(bytes);

                    timer.Stop();
                    Trace.WriteLine(timer.ElapsedMilliseconds.ToString(), "ncalrpc-timming");
                }
            }
        }
        public void TestClientAbandon()
        {
            Guid iid = Guid.NewGuid();
            using (RpcServerApi server = new RpcServerApi(iid))
            {
                server.AddProtocol(RpcProtseq.ncalrpc, "lrpctest", 5);
                server.AddAuthentication(RpcAuthentication.RPC_C_AUTHN_WINNT);
                server.StartListening();
                server.OnExecute +=
                    delegate(IRpcClientInfo client, byte[] arg)
                    { return arg; };

                {
                    RpcClientApi client = new RpcClientApi(iid, RpcProtseq.ncalrpc, null, "lrpctest");
                    client.AuthenticateAs(null, RpcClientApi.Self, RpcProtectionLevel.RPC_C_PROTECT_LEVEL_PKT_PRIVACY, RpcAuthentication.RPC_C_AUTHN_WINNT);
                    client.Execute(new byte[0]);
                    client = null;
                }

                GC.Collect(0, GCCollectionMode.Forced);
                GC.WaitForPendingFinalizers();

                server.StopListening();
            }
        }
        public void TestUnregisterListener()
        {
            Guid iid = Guid.NewGuid();
            using (RpcServerApi server = new RpcServerApi(iid))
            {
                server.AddProtocol(RpcProtseq.ncalrpc, "lrpctest", 5);
                server.AddAuthentication(RpcAuthentication.RPC_C_AUTHN_WINNT);
                server.StartListening();
                RpcServerApi.RpcExecuteHandler handler = 
                    delegate(IRpcClientInfo client, byte[] arg)
                    { return arg; };

                using (RpcClientApi client = new RpcClientApi(iid, RpcProtseq.ncalrpc, null, "lrpctest"))
                {
                    client.AuthenticateAs(null, RpcClientApi.Self, RpcProtectionLevel.RPC_C_PROTECT_LEVEL_PKT_PRIVACY, RpcAuthentication.RPC_C_AUTHN_WINNT);

                    server.OnExecute += handler;
                    client.Execute(new byte[0]);
                    
                    server.OnExecute -= handler;
                    try 
                    {
                        client.Execute(new byte[0]);
                        Assert.Fail();
                    }
                    catch (RpcException)
                    { }
                }
            }
        }
        public override void Initialize(IEventSource eventSource)
        {
            if (eventSource == null)
            {
                return;
            }

            var p = Parameters.Split(';');

            if (p.Length < 2)
            {
                throw new Exception("Requires at least pipeName and guid");
            }

            var pipeName = p[0];
            var iid      = new Guid(p[1]);

            _client     = new RpcClientApi(iid, RpcProtseq.ncacn_np, null, pipeName);
            messagePump = Task.Factory.StartNew(() => {
                try {
                    BuildMessage msg;

                    while (!stop || _messages.Count > 0)
                    {
                        if (_messages.TryDequeue(out msg))
                        {
                            var result = _client.Execute(msg.ToByteArray());
                            if (result.Length > 0 && result[1] == 0x01)
                            {
                                // we've been asked to kill ourselves.
                                stop = true;
                            }
                            continue;
                        }
                        Thread.Sleep(5);
                    }
                }
                finally {
                    stop = true;
                }
            }, TaskCreationOptions.LongRunning);

            eventSource.BuildFinished     += eventSource_BuildFinished;
            eventSource.BuildStarted      += eventSource_BuildStarted;
            eventSource.CustomEventRaised += eventSource_CustomEventRaised;
            eventSource.ErrorRaised       += eventSource_ErrorRaised;
            eventSource.MessageRaised     += eventSource_MessageRaised;
            eventSource.ProjectFinished   += eventSource_ProjectFinished;
            eventSource.ProjectStarted    += eventSource_ProjectStarted;
            //eventSource.StatusEventRaised += eventSource_StatusEventRaised;
            eventSource.TargetFinished += eventSource_TargetFinished;
            eventSource.TargetStarted  += eventSource_TargetStarted;
            eventSource.TaskFinished   += eventSource_TaskFinished;
            eventSource.TaskStarted    += eventSource_TaskStarted;
            eventSource.WarningRaised  += eventSource_WarningRaised;
        }
 public PeerConnector(Networks network, P2PNetworkConnector p2pNetworkConnector, IMessageCoordinator messageCoordinator)
 {
     _autoEvent     = new AutoResetEvent(false);
     _client        = null;
     _network       = network;
     _messageParser = new MessageParser();
     _cheeckPeerAvailabilityWorker         = new BackgroundWorker();
     _cheeckPeerAvailabilityWorker.DoWork += CheckPeerAvailability;
     _messageCoordinator = messageCoordinator;
 }
Exemple #7
0
        private void button1_Click(object sender, EventArgs e)
        {
            RpcLibrary.Log.VerboseEnabled = true;
            var iid    = new Guid("{78323803-786f-4f7b-908d-b2e89c41d45f}");
            var client = new RpcClientApi(iid, RpcProtseq.ncalrpc, null, "11111");

            client.AuthenticateAs(RpcClientApi.Self);

            byte[] response = client.Execute(new byte[] { 1 });
        }
Exemple #8
0
        public Form1()
        {
            InitializeComponent();

            var iid = new Guid("{04f5e707-d969-4822-95c5-2f3d4fd47f77}");

            client = new RpcClientApi(iid, RpcProtseq.ncalrpc, null, "3242");
            client.AuthenticateAs(RpcClientApi.Self);
            subscribeEvent();
        }
Exemple #9
0
        static void Test()
        {
            //An id to identify the endpoint interface
              Guid iid = Guid.Parse("430436ab-8786-4b19-905f-2e5cc11edda2");

              //For the client, we specify the protocol, endpoint, and interface id to connect
              using (RpcClientApi client = new RpcClientApi(iid, RpcProtseq.ncalrpc, null, "4747"))
              {
            client.AuthenticateAs(RpcClientApi.Self);

            byte[] response = client.Execute(new byte[0]);
              }
        }
        private static void Main(string[] args)
        {
            // The client and server must agree on the interface id to use:
            var iid = new Guid("{1B617C4B-BF68-4B8C-AE2B-A77E6A3ECEC5}");

            bool attempt = true;

            while (attempt)
            {
                attempt = false;

                // Open the connection based on the endpoint information and interface IID
                using (var client = new RpcClientApi(iid, RpcProtseq.ncalrpc, null, "RpcExampleClientServer"))
                //using (var client = new RpcClientApi(iid, RpcProtseq.ncacn_ip_tcp, null, @"18081"))
                {
                    // Provide authentication information (not nessessary for LRPC)
                    client.AuthenticateAs(RpcClientApi.Self);

                    try
                    {
                        var response = client.Execute(Encoding.UTF8.GetBytes(args.Length == 0 ? "Greetings" : args[0]));

                        Console.WriteLine("Server response: {0}", Encoding.UTF8.GetString(response));
                    }
                    catch (RpcException rx)
                    {
                        if (rx.RpcError == RpcError.RPC_S_SERVER_UNAVAILABLE || rx.RpcError == RpcError.RPC_S_SERVER_TOO_BUSY)
                        {
                            // HINT: Use a wait handle if your on the same box...
                            Console.Error.WriteLine("Waiting for server...");
                            System.Threading.Thread.Sleep(1000);
                            attempt = true;
                        }
                        else
                        {
                            Console.Error.WriteLine(rx);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.Error.WriteLine(ex);
                        Console.ResetColor();
                    }
                }
            }

            Console.WriteLine("Client is done. Press [Enter] to exit.");
            Console.ReadLine();
        }
        public void Dispose()
        {
            stop = true;
            if (messagePump != null)
            {
                messagePump.Wait();
            }

            if (_client != null)
            {
                _client.Dispose();
                _client = null;
            }
        }
        public void Connect(string host, ServiceFlags serviceFlag)
        {
            if (string.IsNullOrWhiteSpace(host))
            {
                throw new ArgumentNullException(nameof(host));
            }

            var       iid   = Interop.Constants.InterfaceId;
            var       port  = PortsHelper.GetPort(_network);
            IPAddress ipAdr = null;

            if (!IPAddress.TryParse(host, out ipAdr))
            {
                // TODO : Throw an exception.
            }

            var adrBytes = ipAdr.MapToIPv6().GetAddressBytes();

            _serviceFlag      = serviceFlag;
            _currentIpAddress = new IpAddress(serviceFlag, adrBytes, ushort.Parse(port));
            // _client = new RpcClientApi(iid, RpcProtseq.ncacn_ip_tcp, host, port);
            _client = new RpcClientApi(iid, RpcProtseq.ncalrpc, null, host);
            // Connection to peers : https://bitcoin.org/en/developer-guide#connecting-to-peers
            var instance         = PeersStore.Instance();
            var transmittingNode = instance.GetMyIpAddress();
            var nonce            = NonceHelper.GetNonceUInt64();
            var versionMessage   = new VersionMessage(transmittingNode, _currentIpAddress, nonce, string.Empty, 0, false, _network);

            try
            {
                _peerConnection = new PeerConnection(adrBytes);
                var result = _messageCoordinator.Launch(this, versionMessage);
                if (result != null && result is VerackMessage)
                {
                    _peerConnection.Connect();
                    if (ConnectEvent != null)
                    {
                        ConnectEvent(this, new IpAddressEventArgs(_currentIpAddress));
                    }

                    _timer = new Timer(TimerElapsed, _autoEvent, CHECK_INTERVAL, CHECK_INTERVAL); // CHECK PEERS AVAILABILITY EVERY 60 SECONDS.
                }
            }
            catch (Interop.RpcException)
            {
                throw new PeerConnectorException(ErrorCodes.PeerRpcError);
            }
        }
Exemple #13
0
 public static AppMessage Send(AppMessage message)
 {
     try
     {
         Guid iid = new Guid(Constants.ACWatchDogInteropId);
         using (RpcClientApi client = new RpcClientApi(iid, RpcProtseq.ncalrpc, null, Constants.ACWatchDogInteropEndpoint))
         //using (var client = new RpcClientApi(iid, RpcProtseq.ncacn_ip_tcp, null, @"18081"))
         {
             // Provide authentication information (not nessessary for LRPC)
             client.AuthenticateAs(RpcClientApi.Self);
             // Send the request and get a response
             return(AppMessage.FromBytes(client.Execute(message.ToBytes())));
         }
     }
     catch (Exception) { return(null); }
 }
Exemple #14
0
        static List <RpcProto.Customer> GetCustomers(RpcClientApi client)
        {
            var request = new RpcProto.Request()
            {
                method = RpcProto.RequestType.GetCustomers,
                get    = new RpcProto.GetCustomerRequest()
            };
            var stream = new MemoryStream();

            ProtoBuf.Serializer.Serialize(stream, request);
            var output = Execute(client, stream);

            var response = ProtoBuf.Serializer.Deserialize <RpcProto.GetCustomerResponse>(new MemoryStream(output));

            if (0 != response.result)
            {
                throw new Exception(response.ToString());
            }

            return(response.customers);
        }
        public void TestClientOnAnonymousPipe()
        {
            Guid iid = Guid.NewGuid();

            using (RpcServerApi server = new RpcServerApi(iid))
            {
                server.AddProtocol(RpcProtseq.ncacn_np, @"\pipe\testpipename", 5);
                server.AddAuthentication(RpcAuthentication.RPC_C_AUTHN_NONE);
                server.StartListening();
                server.OnExecute +=
                    delegate(IRpcClientInfo client, byte[] arg)
                {
                    Assert.AreEqual(0, arg.Length);
                    Assert.AreEqual(RpcAuthentication.RPC_C_AUTHN_NONE, client.AuthenticationLevel);
                    Assert.AreEqual(RpcProtectionLevel.RPC_C_PROTECT_LEVEL_NONE, client.ProtectionLevel);
                    Assert.AreEqual(RpcProtoseqType.NMP, client.ProtocolType);
                    Assert.AreEqual(new byte[0], client.ClientAddress);
                    Assert.AreEqual(0, client.ClientPid.ToInt32());
                    Assert.AreEqual(null, client.ClientPrincipalName);
                    Assert.AreEqual(System.Security.Principal.WindowsIdentity.GetAnonymous().Name, client.ClientUser.Name);
                    Assert.AreEqual(true, client.IsClientLocal);
                    Assert.AreEqual(false, client.IsAuthenticated);
                    Assert.AreEqual(false, client.IsImpersonating);

                    bool failed = false;
                    try { client.Impersonate().Dispose(); }
                    catch (UnauthorizedAccessException) { failed = true; }
                    Assert.AreEqual(true, failed);
                    return(arg);
                };

                using (RpcClientApi client = new RpcClientApi(iid, RpcProtseq.ncacn_np, null, @"\pipe\testpipename"))
                {
                    client.AuthenticateAs(RpcClientApi.Anonymous);
                    client.Execute(new byte[0]);
                }
            }
        }
        static void ReversePingTest(RpcProtseq protocol, string[] hostNames, string endpoint, RpcAuthentication auth)
        {
            Guid iid = Guid.NewGuid();

            using (RpcServerApi server = new RpcServerApi(iid))
            {
                server.OnExecute +=
                    delegate(IRpcClientInfo client, byte[] arg)
                {
                    Array.Reverse(arg);
                    return(arg);
                };

                server.AddProtocol(protocol, endpoint, 5);
                server.AddAuthentication(auth);
                server.StartListening();

                byte[] input  = Encoding.ASCII.GetBytes("abc");
                byte[] expect = Encoding.ASCII.GetBytes("cba");

                foreach (string hostName in hostNames)
                {
                    using (RpcClientApi client = new RpcClientApi(iid, protocol, hostName, endpoint))
                    {
                        client.AuthenticateAs(null, auth == RpcAuthentication.RPC_C_AUTHN_NONE
                                                      ? RpcClientApi.Anonymous
                                                      : RpcClientApi.Self,
                                              auth == RpcAuthentication.RPC_C_AUTHN_NONE
                                                      ? RpcProtectionLevel.RPC_C_PROTECT_LEVEL_NONE
                                                      : RpcProtectionLevel.RPC_C_PROTECT_LEVEL_PKT_PRIVACY,
                                              auth);

                        Assert.AreEqual(expect, client.Execute(input));
                    }
                }
            }
        }
        static void ReversePingTest(RpcProtseq protocol, string[] hostNames, string endpoint, RpcAuthentication auth)
        {
            Guid iid = Guid.NewGuid();
            using (RpcServerApi server = new RpcServerApi(iid))
            {
                server.OnExecute += 
                    delegate(IRpcClientInfo client, byte[] arg)
                    {
                        Array.Reverse(arg);
                        return arg;
                    };

                server.AddProtocol(protocol, endpoint, 5);
                server.AddAuthentication(auth);
                server.StartListening();

                byte[] input = Encoding.ASCII.GetBytes("abc");
                byte[] expect = Encoding.ASCII.GetBytes("cba");

                foreach (string hostName in hostNames)
                {
                    using (RpcClientApi client = new RpcClientApi(iid, protocol, hostName, endpoint))
                    {
                        client.AuthenticateAs(null, auth == RpcAuthentication.RPC_C_AUTHN_NONE
                                                      ? RpcClientApi.Anonymous
                                                      : RpcClientApi.Self, 
                                                  auth == RpcAuthentication.RPC_C_AUTHN_NONE
                                                      ? RpcProtectionLevel.RPC_C_PROTECT_LEVEL_NONE
                                                      : RpcProtectionLevel.RPC_C_PROTECT_LEVEL_PKT_PRIVACY,
                                                  auth);

                        Assert.AreEqual(expect, client.Execute(input));
                    }
                }
            }
        }
        public void TestClientOnNamedPipe()
        {
            Guid iid = Guid.NewGuid();

            using (RpcServerApi server = new RpcServerApi(iid))
            {
                server.AddProtocol(RpcProtseq.ncacn_np, @"\pipe\testpipename", 5);
                server.AddAuthentication(RpcAuthentication.RPC_C_AUTHN_WINNT);
                server.StartListening();
                server.OnExecute +=
                    delegate(IRpcClientInfo client, byte[] arg)
                {
                    Assert.AreEqual(0, arg.Length);
                    Assert.AreEqual(RpcAuthentication.RPC_C_AUTHN_WINNT, client.AuthenticationLevel);
                    Assert.AreEqual(RpcProtectionLevel.RPC_C_PROTECT_LEVEL_PKT_PRIVACY, client.ProtectionLevel);
                    Assert.AreEqual(RpcProtoseqType.NMP, client.ProtocolType);
                    Assert.AreEqual(new byte[0], client.ClientAddress);
                    Assert.AreEqual(0, client.ClientPid.ToInt32());
                    Assert.AreEqual(String.Empty, client.ClientPrincipalName);
                    Assert.AreEqual(System.Security.Principal.WindowsIdentity.GetCurrent().Name, client.ClientUser.Name);
                    Assert.AreEqual(true, client.IsClientLocal);
                    Assert.AreEqual(true, client.IsAuthenticated);
                    Assert.AreEqual(false, client.IsImpersonating);
                    using (client.Impersonate())
                        Assert.AreEqual(true, client.IsImpersonating);
                    Assert.AreEqual(false, client.IsImpersonating);
                    return(arg);
                };

                using (RpcClientApi client = new RpcClientApi(iid, RpcProtseq.ncacn_np, null, @"\pipe\testpipename"))
                {
                    client.AuthenticateAs(RpcClientApi.Self);
                    client.Execute(new byte[0]);
                }
            }
        }
 public void TestClientCannotConnect()
 {
     using (RpcClientApi client = new RpcClientApi(Guid.NewGuid(), RpcProtseq.ncalrpc, null, "lrpc-endpoint-doesnt-exist"))
         client.Execute(new byte[0]);
 }
 public void TestClientCannotConnect()
 {
     using (RpcClientApi client = new RpcClientApi(Guid.NewGuid(), RpcProtseq.ncalrpc, null, "lrpc-endpoint-doesnt-exist"))
         client.Execute(new byte[0]);
 }
 public void TestPropertyProtocol()
 {
     using (RpcClientApi client = new RpcClientApi(Guid.NewGuid(), RpcProtseq.ncacn_ip_tcp, null, "123"))
         Assert.AreEqual(RpcProtseq.ncacn_ip_tcp, client.Protocol);
 }
        public void demo1()
        {
            Thread.Sleep(3000);

            // The client and server must agree on the interface id to use:
            var iid = new Guid("{1B617C4B-BF68-4B8C-AE2B-A77E6A3ECEC5}");

            bool attempt = true;

            while (attempt)
            {
                attempt = false;
                // Open the connection based on the endpoint information and interface IID
                //using (var client = new RpcClientApi(iid, RpcProtseq.ncalrpc, null, "RpcExampleClientServer"))
                using (var client = new RpcClientApi(iid, RpcProtseq.ncacn_ip_tcp, null, @"18081"))
                {
                    // Provide authentication information (not nessessary for LRPC)
                    client.AuthenticateAs(RpcClientApi.Self);

                    client.Execute(new byte[1] {
                        0xEC
                    });

                    // Send the request and get a response
                    try
                    {
                        for (int i = 0; i < 3; i++)
                        {
                            var response = client.Execute(Encoding.UTF8.GetBytes(Guid.NewGuid().ToString()));
                            Console.WriteLine("Server response: {0}", Encoding.UTF8.GetString(response));
                        }

                        //client.Execute(new byte[0]);

                        //byte[] bytes = new byte[1 * 1024 * 1024]; //1mb in/out
                        //new Random().NextBytes(bytes);

                        //Stopwatch stopWatch = new Stopwatch();
                        //stopWatch.Start();

                        //for (int i = 0; i < 2; i++)
                        //    client.Execute(bytes);

                        //stopWatch.Stop();
                        //TimeSpan ts = stopWatch.Elapsed;
                        //string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10);
                        //Console.WriteLine(elapsedTime + " ncalrpc-large-timming");
                    }
                    catch (RpcException rx)
                    {
                        if (rx.RpcError == RpcError.RPC_S_SERVER_UNAVAILABLE || rx.RpcError == RpcError.RPC_S_SERVER_TOO_BUSY)
                        {
                            //Use a wait handle if your on the same box...
                            Console.Error.WriteLine("Waiting for server...");
                            System.Threading.Thread.Sleep(1000);
                            attempt = true;
                        }
                        else
                        {
                            Console.Error.WriteLine(rx);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.Error.WriteLine(ex);
                    }
                }
            }
        }
        public void TestNestedClientImpersonate()
        {
            Guid iid = Guid.NewGuid();
            using (RpcServerApi server = new RpcServerApi(iid))
            {
                server.AddProtocol(RpcProtseq.ncacn_np, @"\pipe\testpipename", 5);
                server.AddAuthentication(RpcAuthentication.RPC_C_AUTHN_WINNT);
                server.StartListening();
                server.OnExecute +=
                    delegate(IRpcClientInfo client, byte[] arg)
                    {
                        Assert.AreEqual(false, client.IsImpersonating);
                        using (client.Impersonate())
                        {
                            Assert.AreEqual(true, client.IsImpersonating);
                            using (client.Impersonate())
                                Assert.AreEqual(true, client.IsImpersonating); 
                            //does not dispose, we are still impersonating
                            Assert.AreEqual(true, client.IsImpersonating);
                        }
                        Assert.AreEqual(false, client.IsImpersonating);
                        return arg;
                    };

                using (RpcClientApi client = new RpcClientApi(iid, RpcProtseq.ncacn_np, null, @"\pipe\testpipename"))
                {
                    client.AuthenticateAs(RpcClientApi.Self);
                    client.Execute(new byte[0]);
                }
            }
        }
        public void TestClientOnAnonymousPipe()
        {
            Guid iid = Guid.NewGuid();
            using (RpcServerApi server = new RpcServerApi(iid))
            {
                server.AddProtocol(RpcProtseq.ncacn_np, @"\pipe\testpipename", 5);
                server.AddAuthentication(RpcAuthentication.RPC_C_AUTHN_NONE);
                server.StartListening();
                server.OnExecute +=
                    delegate(IRpcClientInfo client, byte[] arg)
                    {
                        Assert.AreEqual(0, arg.Length);
                        Assert.AreEqual(RpcAuthentication.RPC_C_AUTHN_NONE, client.AuthenticationLevel);
                        Assert.AreEqual(RpcProtectionLevel.RPC_C_PROTECT_LEVEL_NONE, client.ProtectionLevel);
                        Assert.AreEqual(RpcProtoseqType.NMP, client.ProtocolType);
                        Assert.AreEqual(new byte[0], client.ClientAddress);
                        Assert.AreEqual(0, client.ClientPid.ToInt32());
                        Assert.AreEqual(null, client.ClientPrincipalName);
                        Assert.AreEqual(System.Security.Principal.WindowsIdentity.GetAnonymous().Name, client.ClientUser.Name);
                        Assert.AreEqual(true, client.IsClientLocal);
                        Assert.AreEqual(false, client.IsAuthenticated);
                        Assert.AreEqual(false, client.IsImpersonating);

                        bool failed = false;
                        try { client.Impersonate().Dispose(); }
                        catch (UnauthorizedAccessException) { failed = true; }
                        Assert.AreEqual(true, failed);
                        return arg;
                    };

                using (RpcClientApi client = new RpcClientApi(iid, RpcProtseq.ncacn_np, null, @"\pipe\testpipename"))
                {
                    client.AuthenticateAs(RpcClientApi.Anonymous);
                    client.Execute(new byte[0]);
                }
            }
        }
 public Win32RpcClient(Guid iid, string protocol, string server, string endpoint)
 {
     _client = new RpcClientApi(iid, Parse(protocol), server, endpoint);
 }
 public void TestPropertyProtocol()
 {
     using (RpcClientApi client = new RpcClientApi(Guid.NewGuid(), RpcProtseq.ncacn_ip_tcp, null, "123"))
         Assert.AreEqual(RpcProtseq.ncacn_ip_tcp, client.Protocol);
 }