gRPC client .NET 5 HttpRequestExceptions

Hello,

I’m developing a POC app with EventStoreDb. I have a wep api project running in docker. I’ve added the docker-compose settings from the getting started guide to my docker-compose.yml. When I run the solution locally, both my web api and ESdb launch in Docker containers. I can access the ES web ui from localhost:2113 as expected.

My gRPC client in my web api controller encounters an HttpRequestException as follows:

var settings = new EventStoreClientSettings
            {
                ConnectivitySettings =
                {
                    Address = new Uri("esdb://127.0.0.1:2113?tls=false")
                }
            };
_esClient = new EventStoreClient(settings);

When making a call with the client, I get the following error:
System.InvalidOperationException: Status(StatusCode="Unavailable", Detail="Error starting gRPC call. HttpRequestException: Connection refused (127.0.0.1:2113) SocketException: Connection refused", DebugException="System.Net.Http.HttpRequestException: Connection refused (127.0.0.1:2113)

If I change the URI to
http://host.docker.internal:2113?tls=false
I get the following exception:

System.InvalidOperationException: Status(StatusCode="Unavailable", Detail="Error starting gRPC call. HttpRequestException: The SSL connection could not be established, see inner exception. IOException: Cannot determine the frame size or a corrupted frame was received.", DebugException="System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception. ---> System.IO.IOException: Cannot determine the frame size or a corrupted frame was received. at System.Net.Security.SslStream.ReceiveBlobAsync[TIOAdapter](TIOAdapter adapter) at System.Net.Security.SslStream.ForceAuthenticationAsync[TIOAdapter](TIOAdapter adapter, Boolean receiveFirst, Byte[] reAuthenticationData, Boolean isApm) at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Boolean async, Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken) --- End of inner exception stack trace ---

I have added the Grps.Net.Client package (v2.38.0). I’m using EventStore.Client.Grpc.Stream (v21.2.0).

Here is my EventStore docker-compose settings:

version: '3.4'

services:
  formsprocessingonorleans:
    image: ${DOCKER_REGISTRY-}formsprocessingonorleans
    build:
      context: .
      dockerfile: FormsProcessingOnOrleans/Dockerfile

  eventstore.db:
    image: eventstore/eventstore:21.6.0-buster-slim
    environment:
      - EVENTSTORE_CLUSTER_SIZE=1
      - EVENTSTORE_RUN_PROJECTIONS=All
      - EVENTSTORE_START_STANDARD_PROJECTIONS=true
      - EVENTSTORE_EXT_TCP_PORT=1113
      - EVENTSTORE_HTTP_PORT=2113
      - EVENTSTORE_INSECURE=true
      - EVENTSTORE_ENABLE_EXTERNAL_TCP=true
      - EVENTSTORE_ENABLE_ATOM_PUB_OVER_HTTP=true
    ports:
      - "1113:1113"
      - "2113:2113"
    volumes:
      - type: volume
        source: eventstore-volume-data
        target: /var/lib/eventstore
      - type: volume
        source: eventstore-volume-logs
        target: /var/log/eventstore

volumes:
  eventstore-volume-data:
  eventstore-volume-logs:

Any suggestions?

Thank you!

So, I was finally able to sort this out.

To run my application in docker (web api and eventstore), my client uri has to be http://host.docker.internal:2113?tls=false.
This resolves the connection refused exception.

Since, my eventstore database was configured as insecure, I had to also set my es client settings to have Insecure = false as well.


    var settings = new EventStoreClientSettings

            {

                ConnectivitySettings =

                {

                    Address = new Uri("http://host.docker.internal:2113?tls=false")

                    ,Insecure = true

                }

            };

            _esClient = new EventStoreClient(settings);

    ```

It was a bit of trial and error since the tooltip for Insecure setting said `True if communicating over a secure channel; otherwise false`.

You tried to use the connection string as EventStoreClientSettings.ConnectivitySettings.Address. It’s not the right way to use the connection string. The query part of the URI is ignored in this case, as ConnectivitySettings allow you to configure all the options using specific properties like Insecure.

If you go to the docs and enter localhost, you get this code sample:

var settings = EventStoreClientSettings
	.Create("esdb://localhost:2113?tls=false");
var client = new EventStoreClient(settings);