| <Project Sdk="Microsoft.NET.Sdk"> | |||||
| <PropertyGroup> | |||||
| <OutputType>Exe</OutputType> | |||||
| <TargetFramework>net5.0</TargetFramework> | |||||
| </PropertyGroup> | |||||
| </Project> |
| using System; | |||||
| namespace Klijent | |||||
| { | |||||
| internal class Program | |||||
| { | |||||
| static void Main(string[] args) | |||||
| { | |||||
| Console.WriteLine("Hello World!"); | |||||
| } | |||||
| } | |||||
| } |
| | |||||
| Microsoft Visual Studio Solution File, Format Version 12.00 | |||||
| # Visual Studio Version 17 | |||||
| VisualStudioVersion = 17.2.32630.192 | |||||
| MinimumVisualStudioVersion = 10.0.40219.1 | |||||
| Global | |||||
| GlobalSection(SolutionProperties) = preSolution | |||||
| HideSolutionNode = FALSE | |||||
| EndGlobalSection | |||||
| GlobalSection(ExtensibilityGlobals) = postSolution | |||||
| SolutionGuid = {94D1D8F8-A619-4DBE-BAE7-65C459AC6CCA} | |||||
| EndGlobalSection | |||||
| EndGlobal |
| using Microsoft.AspNetCore.Hosting; | |||||
| using Microsoft.Extensions.Hosting; | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.IO; | |||||
| using System.Linq; | |||||
| using System.Threading.Tasks; | |||||
| namespace Server | |||||
| { | |||||
| public class Program | |||||
| { | |||||
| public static void Main(string[] args) | |||||
| { | |||||
| CreateHostBuilder(args).Build().Run(); | |||||
| } | |||||
| // Additional configuration is required to successfully run gRPC on macOS. | |||||
| // For instructions on how to configure Kestrel and gRPC clients on macOS, visit https://go.microsoft.com/fwlink/?linkid=2099682 | |||||
| public static IHostBuilder CreateHostBuilder(string[] args) => | |||||
| Host.CreateDefaultBuilder(args) | |||||
| .ConfigureWebHostDefaults(webBuilder => | |||||
| { | |||||
| webBuilder.UseStartup<Startup>(); | |||||
| }); | |||||
| } | |||||
| } |
| { | |||||
| "profiles": { | |||||
| "Server": { | |||||
| "commandName": "Project", | |||||
| "dotnetRunMessages": "true", | |||||
| "launchBrowser": false, | |||||
| "applicationUrl": "http://localhost:5000;https://localhost:5001", | |||||
| "environmentVariables": { | |||||
| "ASPNETCORE_ENVIRONMENT": "Development" | |||||
| } | |||||
| } | |||||
| } | |||||
| } |
| syntax = "proto3"; | |||||
| option csharp_namespace = "Server"; | |||||
| package greet; | |||||
| // The greeting service definition. | |||||
| service Greeter { | |||||
| // Sends a greeting | |||||
| rpc SayHello (HelloRequest) returns (HelloReply); | |||||
| } | |||||
| // The request message containing the user's name. | |||||
| message HelloRequest { | |||||
| string name = 1; | |||||
| } | |||||
| // The response message containing the greetings. | |||||
| message HelloReply { | |||||
| string message = 1; | |||||
| } |
| <Project Sdk="Microsoft.NET.Sdk.Web"> | |||||
| <PropertyGroup> | |||||
| <TargetFramework>net5.0</TargetFramework> | |||||
| </PropertyGroup> | |||||
| <ItemGroup> | |||||
| <Protobuf Include="Protos\greet.proto" GrpcServices="Server" /> | |||||
| </ItemGroup> | |||||
| <ItemGroup> | |||||
| <PackageReference Include="Grpc.AspNetCore" Version="2.34.0" /> | |||||
| </ItemGroup> | |||||
| </Project> |
| using Grpc.Core; | |||||
| using Microsoft.Extensions.Logging; | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Threading.Tasks; | |||||
| namespace Server | |||||
| { | |||||
| public class GreeterService : Greeter.GreeterBase | |||||
| { | |||||
| private readonly ILogger<GreeterService> _logger; | |||||
| public GreeterService(ILogger<GreeterService> logger) | |||||
| { | |||||
| _logger = logger; | |||||
| } | |||||
| public override Task<HelloReply> SayHello(HelloRequest request, ServerCallContext context) | |||||
| { | |||||
| return Task.FromResult(new HelloReply | |||||
| { | |||||
| Message = "Hello " + request.Name | |||||
| }); | |||||
| } | |||||
| } | |||||
| } |
| using Microsoft.AspNetCore.Builder; | |||||
| using Microsoft.AspNetCore.Hosting; | |||||
| using Microsoft.AspNetCore.Http; | |||||
| using Microsoft.Extensions.DependencyInjection; | |||||
| using Microsoft.Extensions.Hosting; | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Threading.Tasks; | |||||
| namespace Server | |||||
| { | |||||
| public class Startup | |||||
| { | |||||
| // This method gets called by the runtime. Use this method to add services to the container. | |||||
| // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 | |||||
| public void ConfigureServices(IServiceCollection services) | |||||
| { | |||||
| services.AddGrpc(); | |||||
| } | |||||
| // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | |||||
| public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | |||||
| { | |||||
| if (env.IsDevelopment()) | |||||
| { | |||||
| app.UseDeveloperExceptionPage(); | |||||
| } | |||||
| app.UseRouting(); | |||||
| app.UseEndpoints(endpoints => | |||||
| { | |||||
| endpoints.MapGrpcService<GreeterService>(); | |||||
| endpoints.MapGet("/", async context => | |||||
| { | |||||
| await context.Response.WriteAsync("Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909"); | |||||
| }); | |||||
| }); | |||||
| } | |||||
| } | |||||
| } |
| { | |||||
| "Logging": { | |||||
| "LogLevel": { | |||||
| "Default": "Debug", | |||||
| "System": "Information", | |||||
| "Grpc": "Information", | |||||
| "Microsoft": "Information" | |||||
| } | |||||
| } | |||||
| } |
| { | |||||
| "Logging": { | |||||
| "LogLevel": { | |||||
| "Default": "Information", | |||||
| "Microsoft": "Warning", | |||||
| "Microsoft.Hosting.Lifetime": "Information" | |||||
| } | |||||
| }, | |||||
| "AllowedHosts": "*", | |||||
| "Kestrel": { | |||||
| "EndpointDefaults": { | |||||
| "Protocols": "Http2" | |||||
| } | |||||
| } | |||||
| } |