title: Grpc.Core.RpcException: 'Status (StatusCode = "Unavailable", Detail = "Error starting gRPC call
body: <p>I'll be immensly grateful if you'd tell me what's causing the problem and how to fix it.</p>
  <p>P.S. Sorry for posting all the code, it's just I'm not sure which exact part is relevant to the problem.</p>
  <h1>Here's the full text of exception:</h1>
  <blockquote>
  <p>Grpc.Core.RpcException: 'Status (StatusCode = &quot;Unavailable&quot;, Detail = &quot;Error starting gRPC call. HttpRequestException: The connection was not established because the destination computer rejected the connection request. SocketException: The connection was not established. the destination computer rejected the connection request. &quot;, DebugException =&quot; System.Net.Http.HttpRequestException: The connection was not established because the destination computer rejected the connection request.
  —-&gt; System.Net.Sockets.SocketException (10061): Connection not established because the destination computer rejected the connection request.
  at System.Net.Http.ConnectHelper.ConnectAsync (String host, Int32 port, CancellationToken cancellationToken)
  —- End of inner exception stack trace —-
  at System.Net.Http.ConnectHelper.ConnectAsync (String host, Int32 port, CancellationToken cancellationToken)
  at System.Net.Http.HttpConnectionPool.ConnectAsync (HttpRequestMessage request, Boolean allowHttp2, CancellationToken cancellationToken)
  at System.Net.Http.HttpConnectionPool.GetHttp2ConnectionAsync (HttpRequestMessage request, CancellationToken cancellationToken)
  at System.Net.Http.HttpConnectionPool.SendWithRetryAsync (HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
  at System.Net.Http.RedirectHandler.SendAsync (HttpRequestMessage request, CancellationToken cancellationToken)
  at Grpc.Net.Client.Internal.GrpcCall<code>2.RunCall (HttpRequestMessage request, Nullable</code>1 timeout) &quot;) '</p>
  </blockquote>
  <h1>Here's the Server code:</h1>
  <p><strong>Program.cs</strong></p>
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Threading.Tasks;
  using Microsoft.Extensions.DependencyInjection;
  using Microsoft.Extensions.Hosting;
  
  namespace GrpcHostServer
  {
      public class Program
      {
          public static void Main(string[] args)
          {
              CreateHostBuilder(args).Build().Run();
          }
  
          public static IHostBuilder CreateHostBuilder(string[] args) =&gt;
              Host.CreateDefaultBuilder(args)
                  .ConfigureServices(services =&gt;
                  {
                      services.AddHostedService&lt;Worker&gt;();
                  });
      }
  }
  </code></pre>
  <p><strong>Worker.cs</strong></p>
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Threading;
  using System.Threading.Tasks;
  using GrpcHostServer.Services;
  using Microsoft.AspNetCore.Builder;
  using Microsoft.AspNetCore.Hosting;
  using Microsoft.AspNetCore.Server.Kestrel.Core;
  using Microsoft.Extensions.DependencyInjection;
  using Microsoft.Extensions.Hosting;
  using Microsoft.Extensions.Logging;
  
  namespace GrpcHostServer
  {
      public class Worker : BackgroundService
      {
          private readonly ILogger&lt;Worker&gt; _logger;
  
          public Worker(ILogger&lt;Worker&gt; logger)
          {
              _logger = logger;
          }
  
          protected override async Task ExecuteAsync(CancellationToken stoppingToken)
          {
              await Host.CreateDefaultBuilder()
                  .ConfigureWebHostDefaults(builder =&gt;
                  {
                      builder
                          .ConfigureKestrel(options =&gt;
                          {
                              options.ListenAnyIP(0, listenOptions =&gt;
                              {
                                  listenOptions.Protocols = HttpProtocols.Http2;
                              });
                          })
                          .UseKestrel()
                          .UseStartup&lt;GrpcServerStartup&gt;();
                  })
                  .Build()
                  .StartAsync(stoppingToken);
          }
      }
  
      public class GrpcServerStartup
      {
          public void ConfigureServices(IServiceCollection services)
          {
              services.AddGrpc();
  
              services.AddSingleton&lt;GreeterService&gt;();
          }
  
          public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
          {
              app.UseRouting();
  
              app.UseEndpoints(endpoints =&gt;
              {
                  endpoints.MapGrpcService&lt;GreeterService&gt;();
              });
          }
      }
  }
  </code></pre>
  <h1>Here's the Client Code</h1>
  <p><strong>Program.cs</strong></p>
  <pre><code>using Grpc.Net.Client;
  using GrpcHostServer;
  using System;
  using System.Threading.Tasks;
  
  namespace GrpcClient
  {
      class Program
      {
          static async Task Main(string[] args)
          {
              var input = new HelloRequest { Name = &quot;Boris&quot; };
              var channel = GrpcChannel.ForAddress(&quot;https://localhost:5001&quot;);
              var client = new Greeter.GreeterClient(channel);
  
              var reply = await client.SayHelloAsync(input);
  
              Console.WriteLine(reply.Message);
  
              Console.ReadLine();
          }
      }
  }
  </code></pre>