Connecting via gRPC - example

Hi!

Bacause documentation is still in progress, can somebody provide the simplest C# example of how to connect via gRPC and send an event to EventStoreDb?

Thank you.

using var client = new EventStoreClient(new EventStoreClientSettings {
  ConnectivitySettings = {
    Address = new Uri("https://localhost:2113") // this is the default
  }
});
// if you have an expected revision use new StreamRevision(...); instead of StreamState.
await client.AppendToStreamAsync("a-stream", StreamState.NoStream,  new [] {  new EventData(Uuid.NewUuid(), "your-type", JsonSerializer.SerializeToUtf8Bytes(e)) });

We also give you extension methods on IServiceCollection if you prefer to resolve it from a container.

Thank you.
Would you be so kind to answer my second question: No gRPC client packages for .net standard ?

We’re in discussions at the moment as to what to do there.

Hi Joao,

This snippet isn’t working for me in dev mode (Docker Desktop running Ubuntu with -e EVENTSTORE_DEV=true)

I’m getting the following error on the server…


System.IO.IOException: The encryption operation failed, see inner exception.
—> Interop+OpenSsl+SslException: Operation failed with error - 5.
— End of inner exception stack trace —
at System.Net.Security.SslStream.WriteAsyncInternal[TWriteAdapter](TWriteAdapter writeAdapter, ReadOnlyMemory1 buffer) at System.IO.Pipelines.StreamPipeWriter.FlushAsyncInternal(CancellationToken cancellationToken) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.PipeWriterHelpers.ConcurrentPipeWriter.FlushAsyncAwaited(ValueTask1 flushTask, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.PipeWriterHelpers.TimingPipeFlusher.TimeFlushAsyncAwaited(ValueTask1 pipeFlushTask, MinDataRate minRate, IHttpOutputAborter outputAborter, CancellationToken cancellationToken) [ 1,29,03:48:54.547,ERR] Unhandled exception while processing "0HM1HRFQA3LOT". System.IO.IOException: The encryption operation failed, see inner exception. ---> Interop+OpenSsl+SslException: Operation failed with error - 5. --- End of inner exception stack trace --- at System.Net.Security.SslStream.WriteAsyncInternal[TWriteAdapter](TWriteAdapter writeAdapter, ReadOnlyMemory1 buffer)
at System.IO.Pipelines.StreamPipeWriter.FlushAsyncInternal(CancellationToken cancellationToken)
at System.IO.Pipelines.StreamPipeWriter.CompleteAsync(Exception exception)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.DuplexPipeStreamAdapter`1.DisposeAsync()
at Microsoft.AspNetCore.Server.Kestrel.Https.Internal.HttpsConnectionMiddleware.InnerOnConnectionAsync(ConnectionContext context)
at Microsoft.AspNetCore.Server.Kestrel.Https.Internal.HttpsConnectionMiddleware.InnerOnConnectionAsync(ConnectionContext context)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.KestrelConnection.ExecuteAsync()


Is there a way I can get around this and bypass SSL with the gRPC client? Just for a trial run?

Thanks!
-Matt

We are working to improve the developer experience in this area. In the meantime you can supply a custom HttpMessageHandler to your settings:

using var client = new EventStoreClient(new EventStoreClientSettings {
  ConnectivitySettings = {
    Address = new Uri("https://localhost:2113") // this is the default,
    CreateHttpMessageHandler = () => new SocketsHttpHandler {
      SslOptions = {
        RemoteCertificateValidationCallback = delegate { return true; } // never do this in production!
      }
    }
});