public void TestUnregisterListener()
        {
            Guid iid = Guid.NewGuid();

            using (ExplicitBytesServer server = new ExplicitBytesServer(iid))
            {
                server.AddProtocol(RpcProtseq.ncalrpc, "lrpctest", 5);
                server.AddAuthentication(RPC_C_AUTHN.RPC_C_AUTHN_WINNT);
                server.StartListening();
                RpcExecuteHandler handler =
                    delegate(IRpcCallInfo client, byte[] arg)
                { return(arg); };
                var endpointBinding = new EndpointBindingInfo(RpcProtseq.ncalrpc, null, "lrpctest");
                using (ExplicitBytesClient client = new ExplicitBytesClient(iid, endpointBinding))
                {
                    client.AuthenticateAs(null, ExplicitBytesClient.Self, RPC_C_AUTHN_LEVEL.RPC_C_AUTHN_LEVEL_PKT_PRIVACY, RPC_C_AUTHN.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 void TestInfiniteRecursiveCalls()
        {
            Guid iid = Guid.NewGuid();

            using (ExplicitBytesServer server = new ExplicitBytesServer(iid))
            {
                server.AddProtocol(RpcProtseq.ncalrpc, "lrpctest", 5);
                server.AddAuthentication(RPC_C_AUTHN.RPC_C_AUTHN_WINNT);
                server.StartListening();
                RpcExecuteHandler handler =
                    delegate(IRpcCallInfo client, byte[] arg)
                {
                    using (ExplicitBytesClient innerClient = new ExplicitBytesClient(iid, new EndpointBindingInfo(RpcProtseq.ncalrpc, null, "lrpctest")))
                    {
                        innerClient.AuthenticateAs(null, ExplicitBytesClient.Self, RPC_C_AUTHN_LEVEL.RPC_C_AUTHN_LEVEL_PKT_PRIVACY, RPC_C_AUTHN.RPC_C_AUTHN_WINNT);
                        return(innerClient.Execute(new byte[0]));
                    }
                };
                server.OnExecute += handler;
                using (ExplicitBytesClient client = new ExplicitBytesClient(iid, new EndpointBindingInfo(RpcProtseq.ncalrpc, null, "lrpctest")))
                {
                    client.AuthenticateAs(null, ExplicitBytesClient.Self, RPC_C_AUTHN_LEVEL.RPC_C_AUTHN_LEVEL_PKT_PRIVACY, RPC_C_AUTHN.RPC_C_AUTHN_WINNT);
                    client.Execute(new byte[0]);
                }
            }
        }
        /// <summary>
        /// Can be over-ridden in a derived class to handle the incomming RPC request, or you can
        /// subscribe to the OnExecute event.
        /// </summary>
        public virtual byte[] Execute(IRpcClientInfo client, byte[] input)
        {
            RpcExecuteHandler proc = _handler;

            if (proc != null)
            {
                return(proc(client, input));
            }
            return(null);
        }
Esempio n. 4
0
        /// <summary>
        /// Can be over-ridden in a derived class to handle the incomming RPC request, or you can
        /// subscribe to the OnExecute event.
        /// </summary>
        public virtual byte[] Execute(IRpcCallInfo call, byte[] input)
        {
            RpcExecuteHandler proc = _handler;

            if (proc != null)
            {
                return(proc(call, input));
            }
            return(null);
        }
        public void LongName()
        {
            var  address = "\\pipe\\127.0.0.1\\1\\test.test\\testLongNameLongNameLongNameLongNameLongNamed0286a6-0b9b-4db1-8659-b715e5db5b3bd0286a6-0b9b-4db1-8659-b715e5db5b3b";
            Guid iid     = Guid.NewGuid();

            using (ExplicitBytesServer server = new ExplicitBytesServer(iid))
            {
                server.AddProtocol(RpcProtseq.ncacn_np, address, 5);
                server.AddAuthentication(RPC_C_AUTHN.RPC_C_AUTHN_WINNT);
                server.StartListening();
                RpcExecuteHandler handler =
                    delegate(IRpcCallInfo client, byte[] arg)
                {
                    return(arg);
                };
                server.OnExecute += handler;
                using (ExplicitBytesClient client = new ExplicitBytesClient(iid, new EndpointBindingInfo(RpcProtseq.ncacn_np, null, address)))
                {
                    client.AuthenticateAs(null, ExplicitBytesClient.Self, RPC_C_AUTHN_LEVEL.RPC_C_AUTHN_LEVEL_PKT_PRIVACY, RPC_C_AUTHN.RPC_C_AUTHN_WINNT);
                    client.Execute(new byte[0]);
                }
            }
        }
 /// <summary>
 /// Disposes of the server and stops listening if the server is currently listening
 /// </summary>
 public void Dispose()
 {
     _handler = null;
     StopListening();
     _handle.Dispose();
 }
 /// <summary>
 /// Disposes of the server and stops listening if the server is currently listening
 /// </summary>
 public void Dispose()
 {
     _handler = null;
     StopListening();
     _handle.Dispose();
 }
Esempio n. 8
0
        internal void Open(ConcurrencyMode concurrency)
        {
            _concurrency = concurrency;
            //Action open = delegate
            {
                try
                {
                    if (_host == null)
                    {
                        RpcExecuteHandler onExecute =
                            delegate(IRpcCallInfo client, byte[] arg)
                        {
                            if (_concurrency == ConcurrencyMode.Single)
                            {
                                //lock (this)
                                //{
                                _operationPending.Reset();
                                try
                                {
                                    return(Invoke(client, _endpoint._contractType, arg));
                                }
                                finally
                                {
                                    _operationPending.Set();
                                }
                                //}
                            }
                            if (_concurrency == ConcurrencyMode.Multiple)
                            {
                                //BUG: need have collection of operations because second operation rewrites state of first
                                _operationPending.Reset();
                                try
                                {
                                    return(Invoke(client, _endpoint._contractType, arg));
                                }
                                finally
                                {
                                    _operationPending.Set();
                                }
                            }

                            throw new NotImplementedException(
                                      string.Format("ConcurrencyMode {0} is note implemented", _concurrency));
                        };
                        _host = RpcRequestReplyChannelFactory.CreateHost(_endpoint._binding, _endpoint._address, _endpoint._uuid);


                        _host.OnExecute += onExecute;
                        _host.StartListening();
                    }
                    //_opened.Set();
                }
                catch (Exception ex)
                {
                    bool handled = ExceptionHandler.AlwaysHandle.HandleException(ex);
                    if (!handled)
                    {
                        throw;
                    }
                }
            };
            //Tasks.Factory.StartNew(open);
            //_opened.WaitOne();
        }
Esempio n. 9
0
 public override void Dispose()
 {
     _handler = null;
     base.Dispose();
 }
Esempio n. 10
0
        public byte[] Execute(byte[] request)
        {
            RpcExecuteHandler onExecuted = OnExecute;

            return(onExecuted(null, request));
        }
Esempio n. 11
0
 public override void Dispose()
 {
     _handler = null;
     base.Dispose();
 }