Library that enables applications to communicate with gRPC services using code-first approach, helps to get around some limitations of gRPC protocol. Provides exception handling. Helps to migrate existing WCF solution to gRPC with minimum effort.
$ dotnet add package ServiceModel.Grpc.MessagePackMarshallerServiceModel.Grpc enables applications to communicate with gRPC services using a code-first approach (no .proto files), helps to get around limitations of gRPC protocol like "only reference types", "exact one input", "no nulls", "no value-types". Provides exception handling. Helps to migrate existing WCF solution to gRPC with minimum effort.
ServiceModel.Grpc.MessagePackMarshaller is package with IMarshallerFactory implementation, based on MessagePack serializer.
Instruct ClientFactory to use MessagePackMarshallerFactory as default marshaller for all clients.
IClientFactory defaultClientFactory
= new ClientFactory(new ServiceModelGrpcClientOptions
{
// set MessagePackMarshaller as default Marshaller
MarshallerFactory = MessagePackMarshallerFactory.Default
});
Instruct ClientFactory to use MessagePackMarshallerFactory for concrete client.
// client factory with default (DataContractMarshallerFactory) marshaller
IClientFactory defaultClientFactory = new ClientFactory();
// set MessagePackMarshaller only for ICalculator client
defaultClientFactory.AddClient<ICalculator>(options =>
{
options.MarshallerFactory = MessagePackMarshallerFactory.Default;
});
Instruct ServiceModel.Grpc code-first to use MessagePackMarshallerFactory as default marshaller for all endpoints.
var builder = WebApplication.CreateBuilder();
// enable ServiceModel.Grpc code-first
builder.Services.AddServiceModelGrpc(options =>
{
// set MessagePackMarshaller as default Marshaller
options.DefaultMarshallerFactory = MessagePackMarshallerFactory.Default;
});
Instruct ServiceModel.Grpc code-first to use MessagePackMarshallerFactory for concrete endpoint.
var builder = WebApplication.CreateBuilder();
// enable ServiceModel.Grpc code-first with default (DataContractMarshallerFactory) marshaller
builder.Services.AddServiceModelGrpc();
// set MessagePackMarshaller only for Calculator endpoint
builder.Services.AddServiceModelGrpcServiceOptions<Calculator>(options =>
{
options.MarshallerFactory = MessagePackMarshallerFactory.Default;
});
Instruct ServiceModel.Grpc code-first to use MessagePackMarshallerFactory.
var server = new Grpc.Core.Server();
// set MessagePackMarshaller for Calculator endpoint
server.Services.AddServiceModelTransient(
()=> new Calculator(),
options =>
{
options.MarshallerFactory = MessagePackMarshallerFactory.Default;
});