mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 22:30:41 +01:00
Add gRPC mock requests and responses through the Administration API. #625
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @AllenXiao565 on GitHub (Aug 27, 2024).
Originally assigned to: @StefH on GitHub.
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
@AllenXiao565 commented on GitHub (Aug 27, 2024):
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.
@StefH commented on GitHub (Aug 27, 2024):
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
@AllenXiao565 commented on GitHub (Aug 27, 2024):
Thank you for your response. It confirms that my assumptions were correct.
@GomesNayagam commented on GitHub (Jan 3, 2025):
@AllenXiao565 i am also struck to automatic grpc call for my project, i wanted to map teh jsons with various request combinaton and response and load the grpc testcontaner