示例#1
0
文件: Proxy.cs 项目: willdarwin/tta
        /// <summary>
        /// Gets the customer by id.  --Robin
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public CustomerBE GetCustomerById(int id)
        {
            GetCustomerByIdRequest request = new GetCustomerByIdRequest();

            request.Id = id;
            GetCustomerByIdResponse response = MyChannelFactory.CreateChannel().GetCustomerById(request);

            if (response.IsFailed)
            {
                throw new Exception("We have a error!" + response.Message);
            }
            return(response.MyCustomer);
        }
示例#2
0
        /// <summary>
        /// Gets the customer by id.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        public GetCustomerByIdResponse GetCustomerById(GetCustomerByIdRequest request)
        {
            CustomerService         service  = new CustomerService();
            GetCustomerByIdResponse response = new GetCustomerByIdResponse();

            try
            {
                response.MyCustomer = service.GetCustomerById(request.Id);
            }
            catch (System.Exception ex)
            {
                response.Message  = ex.ToString();
                response.IsFailed = true;
            }
            return(response);
        }
示例#3
0
        /// <summary>
        /// Gets the customer by id.  --Robin
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public CustomerBE GetCustomerById(int id)
        {
            GetCustomerByIdRequest request = new GetCustomerByIdRequest();

            request.Id = id;
            GetCustomerByIdResponse response = MyChannelFactory.CreateChannel().GetCustomerById(request);

            if (response.IsFailed)
            {
                ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
                log.Error("error", new Exception(response.Message));
                log.Fatal("fatal", new Exception(response.Message));
                throw new Exception("We have a error!");
            }
            return(response.MyCustomer);
        }
示例#4
0
        public async Task ShouldIntercept()
        {
            var channel = new Channel("localhost", 5001, ChannelCredentials.Insecure);

            var options = Options.Create(new CallInterceptorOptions
            {
                ServiceName         = "google.protobuf.CustomerService",
                ResponseType        = "GetCustomerByIdResponse",
                JsonResponseContent = JsonConvert.SerializeObject(new GetCustomerByIdResponse {
                    Customer = new Customer {
                        Id = 1, FirstName = "Ed", LastName = "Torsten"
                    }
                })
            });

            var interceptor = new CallInterceptor(options, channel);

            var client = new CustomerService.CustomerServiceClient(interceptor);
            GetCustomerByIdResponse response = await client.GetCustomerByIdAsync(new GetCustomerByIdRequest());

            Assert.Equal(1, response.Customer.Id);
            Assert.Equal("Ed", response.Customer.FirstName);
            Assert.Equal("Torsten", response.Customer.LastName);
        }