public async Task <int> CreateAsync <TSource, TDestination>(TSource item)
            where TSource : class
            where TDestination : class
        {
            _token = await _jwtTokenService.CheckTokenAsync(_token);

            var channel = GrpcChannel.ForAddress("https://localhost:5001");
            var client  = new Courses.CoursesClient(channel);

            var headers = new Metadata();

            headers.Add("Authorization", $"Bearer {_token.Token}");

            var reply = await client.CreateCourseAsync(
                new CourseMessage { Title = "BestTitle" }, headers);

            /*  var channel = await CreateAuthenticatedChannel("https://localhost:5001");
             * var client = new CoursesService.CoursesServiceClient(channel);
             */
            /* var serviceFactory = _grpcServiceFactory.GetService<TSource>();
             * serviceFactory
             *
             * var reply = await client.CreateCourseAsync(
             *  new CourseMessage { Title = "BestTitle" });.*/

            return(reply.Id);
        }
Пример #2
0
        static async Task Main(string[] args)
        {
            //AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);

            var channel = GrpcChannel.ForAddress("https://localhost:5001");

            //var client = new Greeter.GreeterClient(channel);

            //var reply = await client.SayHelloAsync(
            //    new HelloRequest { Name = "GreeterClient" });

            //var result = "Greeting: " + reply.Message;



            var client = new Courses.CoursesClient(channel);

            var reply = await client.CreateCourseAsync(
                new CourseMessage { Title = "BestTitle" });

            var result = reply.Title;

            Console.WriteLine(result);


            Console.WriteLine("Press any key to exit...");



            Console.ReadKey();
        }
        public async Task <int> CreateAsync(CourseDTO item)
        {
            _token = await _jwtTokenService.CheckTokenAsync(_token);

            var headers = new Metadata();

            headers.Add("Authorization", $"Bearer {_token.Token}");

            var course = _mapper.Map <CourseMessage>(item);//new CourseMessage { Title = "BestTitle" }

            var reply = await _coursesClient.CreateCourseAsync(course, headers);

            return(reply.Id);
        }