Пример #1
0
        private static void Main(string[] args)
        {
            Thread.Sleep(10000);
            var containerBuilder = new ContainerBuilder();
            var builder          = new ServiceHostClientBuilder(containerBuilder).UseRpcForTransfer();

            using (var host = builder.Build())
            {
                ITransportClient client = host.Container.Resolve <ITransportClientFactory>()
                                          .CreateClient(new ServerAddress("127.0.0.1", 8008));

                //ITransportClient client = container.Resolve<ITransportClientFactory>()
                //    .DecorationFactory(container.Resolve<ISerializer>())
                //    .CreateClient(new ServerAddress("127.0.0.1", 8007));
                RemoteCallData sendMessage = new RemoteCallData
                {
                    ServiceId  = "base/fastdfs",
                    Parameters = new Dictionary <string, object>
                    {
                        { "message", 12 },
                        { "myout", 122 }
                    }
                };

                RemoteCallBackData result = client.SendAsync(sendMessage).Result;
                Console.Write(result.Result.ToString());
                Console.ReadLine();
            }
        }
Пример #2
0
        /// <summary>
        /// 服务内部调用方法
        /// </summary>
        /// <param name="serverAddress">服务地址</param>
        /// <param name="sendMessage">请求内容</param>
        public static async Task <T> InternalCall <T>(List <ServerAddress> service, RemoteCallData sendMessage)
        {
            ContainerBuilder containerBuilder = new ContainerBuilder();

            Core.Client.IServiceHostClientBuilder builder = new ServiceHostClientBuilder(containerBuilder).UseRpcForTransfer()
                                                            .UsePollingAddressSelector(BalanceType.RoundRobin);
            using (Core.IServiceHost host = builder.Build())
            {
                IAddressSelector addressSelector = host.Container.Resolve <IAddressSelector>();
                ServerAddress    desc            = await addressSelector.GetAddressAsync(service);

                ITransportClient client = host.Container.Resolve <ITransportClientFactory>()
                                          .CreateClient(desc);

                RemoteCallBackData result = client.SendAsync(sendMessage).Result;
                return(JsonConvert.DeserializeObject <T>(result.Result.ToString()));
            }
        }