mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 22:30:41 +01:00
Does Aspire support enabling HTTP/2? #727
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 @Allen0117 on GitHub (Nov 20, 2025).
Originally assigned to: @StefH on GitHub.
I recently discovered that WireMock.NET supports Aspire, and I’ve started using it successfully. However, in real products we inevitably encounter gRPC, so naturally I wanted to use WireMock.NET with Aspire to mock gRPC as well. Unfortunately, I couldn’t find any related documentation, and after tracing through the code, I also noticed that none of the external customization parameters seem to support this.
So I’d like to ask: is this something that’s simply not planned to be supported, or will it be supported in the future?
@StefH commented on GitHub (Nov 23, 2025):
@Allen0117
I think that exposing
UseHttp2inWireMockServerArgumentsshould work?@StefH commented on GitHub (Nov 23, 2025):
https://github.com/wiremock/WireMock.Net/pull/1383
@Allen0117 commented on GitHub (Nov 23, 2025):
I think placing UseHttp2 under WireMockServerArguments does make gRPC work properly. As for AddProtoDefinition, would you prefer it to use the mapper’s given configuration? Or how would you like it to be used within Aspire?
@StefH commented on GitHub (Nov 23, 2025):
You can try preview
1.16.0-ci-110628
https://wiremock.org/dotnet/myget-preview-versions/
@Allen0117 commented on GitHub (Nov 24, 2025):
Hi @StefH I’d like to understand the issue regarding the gRPC port. In TestContainer, I can use AddUrl("grpc://*:9090"), but I’m not sure how to define this in Aspire.
@StefH commented on GitHub (Nov 24, 2025):
Can you try
1.16.0-ci-110634
This one has a constructor
.AddWireMock("apiservice", ["http://:8080", "grpc://:9090"])
@StefH commented on GitHub (Nov 27, 2025):
@Allen0117
Could you test it?
@Allen0117 commented on GitHub (Nov 28, 2025):
Sorry @StefH I’m currently validating it in parallel with WireMockTestContainer, and I hope the approaches used on both sides can be as similar as possible.
Do you have a pending time on your side? If so, I can focus on WireMockAspire first.
@StefH commented on GitHub (Nov 28, 2025):
Testcontainers did already support https grpc.
See also my unit tests.
So I think you can focus on Aspire.
@Allen0117 commented on GitHub (Nov 28, 2025):
I’ve already verified that the Testcontainers case works without issues.
I simply want to see whether the same approach can also be used in Aspire, and as mentioned earlier, I hope the usage patterns can be as similar as possible.
For now, I’ll focus on the Aspire part first.
Additionally, I noticed that when Testcontainers uses WithMapping or WithMount for JSON files, they are correctly placed under /app/__admin/mappings, but validation still results in errors. I also saw that others have reported the same issue in the past (e.g., GitHub issue #1274). I’m not sure if this is the expected behavior?
@StefH commented on GitHub (Nov 28, 2025):
Thanks a lot. If you can test this and it works I can merge the PR and create a new version.
I need to find time to investigate this in more detail...
@Allen0117 commented on GitHub (Nov 29, 2025):
Hi @StefH These are the issues I’m currently encountering in the tests, using both the constructor and the arguments approach.
constructor
builder.AddWireMock(resourceName, ["http://:9093", "grpc://:9090"])will show errorUnhandled exception. System.ArgumentException: The URL http://:9093 is not valid. at AspireBefore switching to the new approach, I expected to use it the way shown in the screenshot.

@StefH commented on GitHub (Nov 29, 2025):
@Allen0117
1
Sorry, I did write the wrong URLs:
It should be with a star:
"http://*:8080", "grpc://*:9090"2
Good point.
New code can be used like:
Can you try
1.16.0-ci-110644
@Allen0117 commented on GitHub (Nov 29, 2025):
Hi @StefH Aspire is currently running smoothly, as shown in the screenshot.
I tested both HTTP and gRPC separately. The HTTP endpoint responds correctly, but the gRPC call returns
“Error: Received HTTP status code 404.”Looking into the error details, I saw the following message:
“Getting a Request MatchResult for Mapping '351f0240-bba0-4bcb-93c6-1feba0fe0004' failed. This mapping will not be evaluated. Exception: System.ArgumentException: Error parsing proto definition. Error(s): syntax error: 'my-greeter', unknown error (Parameter 'protoDefinition')”My guess is that, similar to TestContainers, we need to provide something like:
.AddProtoDefinition("my-greeter", protoContent)However, I noticed that this method is currently not available.After that, I updated my setup by following the example from
protobuf-mapping-1.json (mixing the proto file and JSON), as shown here:
https://github.com/wiremock/WireMock.Net/blob/master/test/WireMock.Net.Tests/__admin/mappings/protobuf-mapping-1.json
I then ran Aspire and tested it again, and it seems to be working now (see screenshot).
I’d like to ask: is this the expected way Aspire is supposed to handle gRPC usage?
@StefH commented on GitHub (Nov 29, 2025):
AddProtoDefinition(id, xxx)has been added to the arguments and should work the same as testcontainers1.16.0-ci-110646
@Allen0117 commented on GitHub (Nov 29, 2025):
Hi @StefH I trying 1.16.0-ci-110646 and write code like screenshto, but when call grpc will show error
Getting a Request MatchResult for Mapping '351f0240-bba0-4bcb-93c6-1feba0fe0004' failed. This mapping will not be evaluated. Exception: System.ArgumentException: Error parsing proto definition. Error(s): syntax error: 'my-greeter',unknown error (Parameter 'protoDefinition')Proto file using : https://github.com/wiremock/WireMock.Net/blob/master/test/WireMock.Net.Tests/__admin/mappings/greet.proto
json file using:
https://github.com/wiremock/WireMock.Net/blob/master/test/WireMock.Net.Tests/__admin/mappings/protobuf-mapping-4.json
@Allen0117 commented on GitHub (Nov 29, 2025):
Using the same approach in TestContainers also seems to cause issues.
When I load the .proto details through AddProtoDefinition and then assign the .json file using WithMappings (similar to protobuf-mapping-4.json, where the .proto details are removed), the test produces the same error as in Aspire.
Sorry about this — I’ll be away from work next week, so I won’t be able to respond promptly to your updates or help with verification.
I apologize for any inconvenience this may cause.
@StefH commented on GitHub (Nov 29, 2025):
I can also reproduce this error in Aspire.
However, this test for TestContainers does work?
44388ce80d/test/WireMock.Net.Tests/Testcontainers/TestcontainersTests.Grpc.cs (L139)Can you spot the difference?
@Allen0117 commented on GitHub (Nov 29, 2025):
Hi @StefH
public async Task WireMockContainer_Build_Grpc_ProtoDefinitionAtServerLevel_UsingGrpcGeneratedClient()
does indeed work correctly.
The difference is success that protobuf-mapping-4.json is added using
httpClient.PostAsync("/__admin/mappings", ...),
while in my failing case, all the .json files were injected through WithMapping.
Fail Code screen shot
@StefH commented on GitHub (Nov 30, 2025):
@Allen0117
Thank you very much, your last comment pointed me in the right direction!
Fixed version is:
1.16.0-ci-110650
@Allen0117 commented on GitHub (Dec 7, 2025):
Sorry @StefH , I just saw your message after returning from my leave. I’ll test it right away.
@Allen0117 commented on GitHub (Dec 7, 2025):
Hi @StefH After running the tests, neither Aspire nor TestContainer works with version 1.16.0-ci-110650. The error is as follows:
12/07/2025 07:06:37 [Error] : Getting a Request MatchResult for Mapping '351f0240-bba0-4bcb-93c6-1feba0fe0004' failed. This mapping will not be evaluated. Exception: System.ArgumentException: Error parsing proto definition. Error(s): syntax error: 'my-greeter',unknown error (Parameter 'protoDefinition') at ProtoBufJsonConverter.Converter.GetDataAsync(Int32 key, String protoDefinition, IProtoFileResolver protoFileResolver, CancellationToken cancellationToken) at ProtoBufJsonConverter.Extensions.DictionaryExtensions.GetOrAddAsync[TKey,TValue](IDictionary2 dictionary, TKey key, Func2 valueFactory) at ProtoBufJsonConverter.Converter.ParseAsync(ConvertRequest request, CancellationToken cancellationToken) at ProtoBufJsonConverter.Converter.ConvertAsync(ConvertToObjectRequest request, CancellationToken cancellationToken) at WireMock.Matchers.ProtoBufMatcher.DecodeAsync(Byte[] input, Boolean throwException, CancellationToken cancellationToken) at WireMock.Matchers.ProtoBufMatcher.IsMatchAsync(Byte[] input, CancellationToken cancellationToken) 12/07/2025 07:06:37 [Warn] : HttpStatusCode set to 404 : No matching mapping foundprotobuf-mapping-4.json content
{ "Guid": "351f0240-bba0-4bcb-93c6-1feba0fe0004", "Title": "ProtoBuf Mapping 4", "Request": { "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "/greet.Greeter/SayHello", "IgnoreCase": false } ] }, "Methods": [ "POST" ], "Body": { "Matcher": { "Name": "ProtoBufMatcher", "ProtoBufMessageType": "greet.HelloRequest" } } }, "Response": { "BodyAsJson": { "message": "hello {{request.BodyAsJson.name}} {{request.method}}" }, "UseTransformer": true, "TransformerType": "Handlebars", "TransformerReplaceNodeOptions": "EvaluateAndTryToConvert", "Headers": { "Content-Type": "application/grpc" }, "TrailingHeaders": { "grpc-status": "0" }, "ProtoBufMessageType": "greet.HelloReply" }, "ProtoDefinition": "my-greeter" }@Allen0117 commented on GitHub (Dec 7, 2025):
Hi @StefH
I've figured it out. The setup now works correctly when using the Mapping approach.
Initially, I used the wrong method call arguments.AddProtoDefinition. After tracing the code a bit, I noticed that you placed WireMockServerLifecycleHook inside WithProtoDefinition, so switching to that resolved the issue.
I'm not sure if this is the intended usage. If it is, I’d suggest making arguments.AddProtoDefinition non-public to prevent misuse.
I'll test the TestContainer part later.
@StefH commented on GitHub (Dec 7, 2025):
@Allen0117
Thank you for testing
I've updated my code to always call register the WireMockServerLifecycleHook.
Also the method has been renamed to "WithProtoDefinition" --> both should work now
See preview:
1.16.0-ci-110658
@Allen0117 commented on GitHub (Dec 7, 2025):
test "1.16.0-ci-110658" version is ok, I believe this version addresses the issue I initially raised and achieves the intended results. Please help merge it back into the official release. Thank you support.