Example #1
0
        // POST api/values
        public IEnumerable <int> Post([FromBody] CacheRequestMessage value)
        {
            //int[] a = store.Search(x => x.Contains("abc"));

            //////createDynamic();

            //////if (_client.State == WebSocketState.Open)
            //////{
            //////    string msg = Guid.NewGuid().ToString();
            //////    ArraySegment<byte> bytesToSend = new ArraySegment<byte>(System.Text.Encoding.UTF8.GetBytes(msg));
            //////    _client.SendAsync(bytesToSend, WebSocketMessageType.Text, true, CancellationToken.None).Wait();
            //////}

            HelloReply response = _client.SayHello(HelloRequest.CreateBuilder().SetName(Guid.NewGuid().ToString()).Build());

            Debug.WriteLine("OK: " + response.Message);

            return(new int[] { 3, 4, 5, 6 });
        }
Example #2
0
        //////static readonly ClientWebSocket _client = new ClientWebSocket();
        static table1col1Controller()
        {
            for (int i = 0; i < limit; i++)
            {
                store.Add(i, Guid.NewGuid().ToString());
            }
            //////try
            //////{
            //////    _client.ConnectAsync(new Uri("ws://*****:*****@"localhost", "50051").Authenticate(RpcAuthenticationType.None));
                _client = new Greeter(RpcClient.ConnectRpc(iid, "ncacn_ip_tcp", @"localhost", "50051").Authenticate(RpcAuthenticationType.Self));
                HelloReply response = _client.SayHello(HelloRequest.CreateBuilder().SetName(Guid.NewGuid().ToString()).Build());
                Debug.WriteLine("OK: " + response.Message);
            }
            catch { }

            //using (Greeter client = new Greeter(RpcClient
            //                    .ConnectRpc(iid, "ncacn_ip_tcp", @"localhost", "50051")
            //                    .Authenticate(RpcAuthenticationType.Self)
            //                    //.Authenticate(RpcAuthenticationType.None)
            //                    ))
            //{
            //    HelloReply response = client.SayHello(HelloRequest.CreateBuilder().SetName(Guid.NewGuid().ToString()).Build());
            //    Console.WriteLine("OK: " + response.Message);
            //}
        }
        static void Main(string[] args)
        {
            args    = new[] { "" };
            args[0] = "listen";

            switch (args[0].ToLower())
            {
            case "listen":
            {
                ////using (RpcServer.CreateRpc(IID, new Impersonation(new MyService.ServerStub(new Implementation())))
                //using (RpcServer.CreateRpc(IID, new Impersonation(new Greeter.ServerStub(new Implementation_Greeter())))
                //    //.AddAuthentication(CSharpTest.Net.RpcLibrary.RpcAuthentication.RPC_C_AUTHN_NONE)
                //    //.AddAuthNegotiate()
                //    .AddProtocol("ncacn_ip_tcp", "50051")
                //    //.AddProtocol("ncacn_np", @"\pipe\Greeter")
                //    ////.AddProtocol("ncalrpc", "MyService")
                //    //.AddProtocol("ncalrpc", "Greeter")
                //    .StartListening())
                //{
                //    Console.WriteLine("Waiting for connections...");
                //    Console.ReadLine();
                //}


                Guid iid = Marshal.GenerateGuidForType(typeof(IGreeter));
                using (RpcServer.CreateRpc(iid, new Greeter.ServerStub(new Anonymous_Greeter()))
                       //.AddAuthNegotiate()
                       .AddAuthentication(CSharpTest.Net.RpcLibrary.RpcAuthentication.RPC_C_AUTHN_NONE)
                       .AddAuthNegotiate()
                       .AddProtocol("ncacn_ip_tcp", "50051")
                       //.AddProtocol("ncalrpc", "Greeter")
                       .StartListening())
                {
                    Console.WriteLine("Waiting for connections...");
                    string name = "123";         // Console.ReadLine();


                    using (Greeter client = new Greeter(RpcClient
                                                        .ConnectRpc(iid, "ncacn_ip_tcp", @"localhost", "50051")
                                                        .Authenticate(RpcAuthenticationType.Self)
                                                        //.Authenticate(RpcAuthenticationType.None)
                                                        ))
                    {
                        HelloReply response = client.SayHello(HelloRequest.CreateBuilder().SetName(name).Build());
                        Console.WriteLine("OK: " + response.Message);
                    }
                    Console.ReadLine();
                }

                //Guid iid = Marshal.GenerateGuidForType(typeof(IBookService));
                //using (RpcServer.CreateRpc(iid, new BookService.ServerStub(new Anonymous_BookService()))
                //    .AddProtocol("ncacn_ip_tcp", "50051")
                //    .AddProtocol("ncalrpc", "BookService")
                //    .StartListening())
                //{
                //    Console.WriteLine("Waiting for connections...");
                //    Console.ReadLine();
                //}


                break;
            }

            case "send-lrpc":
            {
                using (MyService client = new MyService(
                           RpcClient.ConnectRpc(IID, "ncalrpc", null, "MyService")
                           .Authenticate(RpcAuthenticationType.Self)))
                {
                    MyResponse response = client.Send(
                        MyRequest.CreateBuilder().SetMessage("Hello via LRPC!").Build());
                }
                break;
            }

            case "send-tcp":
            {
                using (MyService client = new MyService(
                           RpcClient.ConnectRpc(IID, "ncacn_ip_tcp", @"localhost", "8080")
                           .Authenticate(RpcAuthenticationType.Self)))
                {
                    MyResponse response = client.Send(
                        MyRequest.CreateBuilder().SetMessage("Hello via Tcp/Ip!").Build());
                }
                break;
            }

            case "send-np":
            {
                using (MyService client = new MyService(
                           RpcClient.ConnectRpc(IID, "ncacn_np", @"\\localhost", @"\pipe\MyService")
                           .Authenticate(RpcAuthenticationType.Self)))
                {
                    MyResponse response = client.Send(
                        MyRequest.CreateBuilder().SetMessage("Hello via Named Pipe!").Build());
                }
                break;
            }

            case "send-anon":
            {
                using (MyService client = new MyService(
                           RpcClient.ConnectRpc(IID, "ncacn_np", @"\\localhost", @"\pipe\MyService")
                           .Authenticate(RpcAuthenticationType.Anonymous)))
                {
                    try
                    {
                        MyResponse response = client.Send(
                            MyRequest.CreateBuilder().SetMessage("Hello from Anonymous!").Build());
                    }
                    catch (Exception e)
                    {
                        Console.Error.WriteLine(e);
                    }
                }
                break;
            }
            }
        }