Closed AllenXiao565 closed 2 months ago
var grpcWireMockAdminApi = RestClient.For<IWireMockAdminApi>("http://localhost:49331");
await grpcWireMockAdminApi.PostMappingAsync(new MappingModel { Request = new RequestModel { Methods = ["POST"], Path = "/BonusTransaction/ProcessCasinoBonus", Body = new BodyModel { Matcher = new MatcherModel() { ProtoBufMessageType = "ProcessCasinoBonusRequest" } } }, Response = new ResponseModel() { StatusCode = HttpStatusCode.OK, ProtoDefinition = "GrpcBonusTransaction2", Headers = new Dictionary<string, object>() { { "Content-Type", "application/grpc"} }, TrailingHeaders = new Dictionary<string, object>() { { "grpc-status", "0" } }, ProtoBufMessageType = "CasinoProcessResponse", BodyDestination = null, BodyAsJson = new CasinoProcessResponse { WinLostDate = 1690816326000, Status = 1 }, UseTransformer = true, TransformerType = "Handlebars", TransformerReplaceNodeOptions = "EvaluateAndTryToConvert", UseTransformerForBodyAsFile = false } });
The code above is my current attempt, but when I run it, I get the following error: Unhandled exception. RestEase.ApiException: POST "http://localhost:XXX/__admin/mappings" failed because the response status code does not indicate success. I think this might be happening because the server does not support HTTP requests for mappings when UseHttp2 is enabled.
The admin-api can be used to manage your mappings (which can be mappings which use grpc). Once the mappings are defined, WireMock.Net will behave like a Grpc server. The admin admin cannot be used to send Grpc request to.
See this example project for some info: https://github.com/WireMock-Net/WireMock.Net/tree/master/examples/WireMock.Net.Console.GrpcClient
Thank you for your response. It confirms that my assumptions were correct.
Based on the introduction and exercises from the blog post on how to use WireMock.NET with gRPC, I was able to successfully complete the first step. However, I got stuck when trying to move on to the next step. My expectation was to be able to use the Administration API to send requests and responses for simulating gRPC responses, but it seems like this is not currently supported. I was wondering if you have any other suggestions