gRPC Web

Babel Licensing Service supports gRPC Web because it enables a wide range of applications, including Xamarin and UWP, to interact with gRPC services. By using gRPC-Web, these applications can make direct calls to gRPC services using the gRPC Web client and Protobuf.

The significance of gRPC Web lies in its compatibility with HTTP/1.1 and browsers. While traditional gRPC relies on HTTP/2 features, which are not supported by all browsers and technologies, gRPC Web has a slightly different protocol that makes it compatible with HTTP/1. This allows browser applications, including those built with Xamarin and UWP, to benefit from the high performance and low network usage of binary messages provided by gRPC.

gRPC Web eliminates the need for separate communication mechanisms or workarounds for Xamarin clients, making it easier to integrate Babel Licensing Service into a wide range of applications, including those targeting UWP platforms.

Server

To enable gRPC-Web in Babel Licensing Service, you need to make the following configuration changes:

  1. Update the Kestrel endpoint configuration in the appsettings.json file. Ensure that the "Protocols" property includes "Http1AndHttp2" to enable both HTTP/1.1 and HTTP/2 protocols:

"Endpoints": {
  "gRPC": {
    "Url": "https://localhost:5005",
    "Protocols": "Http1AndHttp2"
    // other properties...
  }
}
  1. Set the "EnableGrpcWeb" property in the "Application" section of the appsettings.json file to true. This indicates that gRPC-Web should be enabled. For example:

"Application": {
  "EnableGrpcWeb": true,
  // other properties...
}
  1. Enable SSL/TLS support in the Babel Licensing Service project to ensure protocol negotiation through the ALPS capabilities provided by the TLS layer extension.

"Endpoints": {
  "gRPC": {
    "Url": "https://localhost:5005",
    "Protocols": "Http1AndHttp2",
    "Certificate": {
      "AllowInvalid": true,
      "Path": "<cert file>.pfx",
      "Password": "<cert password>"
    }
  }
}

By configuring Babel Licensing Service with these settings, you enable gRPC-Web support, allowing browser-based client applications, including Xamarin and UWP applications, to communicate with the service using gRPC-Web. This enables seamless integration and efficient communication between the client applications and the Babel Licensing Service, leveraging the benefits of gRPC for secure and high-performance data transmission.

Client

To enable gRPC Web in your client application to connect with Babel Licensing Service, follow these steps:

  1. Add the NuGet package reference to your project:

Grpc.Net.Client.Web
  1. In your code, configure the BabelLicensing client using the BabelLicensing.Configure method. Set the ServiceUrl property to the URL of your Babel Licensing Service endpoint.

BabelLicensing.Configure(config => {
    config.ServiceUrl = "https://localhost:5005";
    var certificate = new X509Certificate2("<cert file>.pfx", "<cert password>");

    config.ChannelOptions = new GrpcChannelOptions();
    config.ChannelOptions.HttpHandler = new GrpcWebHandler(new HttpClientHandler() {
        ClientCertificates = { certificate },
        ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
    });
});

In the code snippet above, replace <cert file>.pfx with the path to your SSL/TLS certificate file and <cert password> with the password for the certificate.

This configuration sets up the gRPC Web client using GrpcChannelOptions and GrpcWebHandler. It allows the client to communicate securely with the Babel Licensing Service using the gRPC Web protocol over HTTPS. The GrpcWebHandler is configured with a custom HttpClientHandler that includes the client certificate and accepts any server certificate for development purposes.

In a production environment, make sure to properly handle and secure certificates by setting AllowInvalid to false and by removing the ServerCertificateCustomValidationCallback in the client code.

With this configuration, your client application can now connect to the Babel Licensing Service using gRPC Web, enabling secure and efficient communication between the client and the service.

Last updated