mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-08-01 01:38:35 +02:00
Using google.protobuf.Empty as response results in a bad gRPC response #618
Closed
opened 2025-12-29 15:28:30 +01:00 by adam
·
50 comments
No Branch/Tag Specified
master
1341-mapping-json
stef-aspire-tests-updates
bug/973-TinyMapper
bug/1149-AppendGuidToSavedMappingFile
feature/1150-DockerImageVersion
61
stef-1108
stef-1097
stef-1083-MessageOptions_Type_Conflict
stef-1062-logger
stef-IgnoreOpenApiErrors
stef-928-TypeLoadException-FluentAssertions-net472
nunit
stef-849
stef-847-regex-questionmark
http_verb
WireMockServerContext
webapp
ai
CommandLineArgumentsParser
2.13.0
2.12.0
2.11.0
2.10.0
2.9.0
2.8.0
2.7.0
2.6.0
2.5.0
2.4.0
2.3.0
2.2.0
2.1.0
2.0.0
1.25.0
1.24.0
1.23.0
1.22.0
1.21.0
1.20.0
1.19.0
1.18.0
1.17.0
1.16.0
1.15.0
1.14.0
1.13.0
1.12.0
1.11.2
1.11.0
1.10.1
1.10.0
1.9.1
1.9.0
1.8.18
1.8.17
1.8.16
1.8.15
1.8.14
1.8.13
1.8.12
1.8.11
1.8.10
1.8.9
1.8.8
1.8.7
1.8.6
1.8.5
1.8.3
1.8.2
1.8.1
1.8.0
1.7.4
1.7.3
1.7.2
1.7.1
1.7.0
1.6.12
1.6.11
1.6.10
1.6.9
1.6.8
1.6.7
1.6.6
1.6.5
1.6.4
1.6.3
1.6.2
1.6.1
1.6.0
1.5.62
1.5.61
1.5.60
1.5.59
1.5.58
1.5.57
1.5.56
1.5.55
1.5.54
1.5.53
1.5.52
1.5.51
1.5.50
1.5.49
1.5.48
1.5.47
1.5.46
1.5.45
1.5.44
1.5.43
1.5.42
1.5.41
1.5.40
1.5.39
1.5.38
1.5.37
1.5.36
1.5.35
1.5.34
1.5.33
1.5.32
1.5.31
1.5.30
1.5.29
1.5.28
1.5.27
1.5.26
1.5.25
1.5.24
1.5.23
1.5.22
1.5.21
1.5.20
1.5.19
1.5.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4.11
1.0.4.10
1.0.4.9
1.0.4.8
1.0.4.7
1.0.4.6
1.0.4.5
1.0.4.4
1.0.4.3
1.0.4.2
1.0.4.1
1.0.4.0
1.0.3.20
1.0.3.19
1.0.3.18
1.0.3.17
1.0.3.16
1.0.3.15
1.0.3.14
1.0.3.13
1.0.3.12
1.0.3.11
1.0.3.10
1.0.3.9
1.0.3.8
1.0.3.7
1.0.3.6
1.0.3.5
1.0.3.4
1.0.3.3
1.0.3.2
1.0.3.1
1.0.3.0
1.0.2.13
1.0.2.12
1.0.2.11
1.0.2.10
1.0.2.9
1.0.2.8
1.0.2.7
1.0.2.6
1.0.2.5
1.0.2.4
1.0.2.1
1.0.2.0
1.0.1.5
1.0.1.3
1.0.1.2
1.0.1.1
1.0.0.0
Milestone
No items
No Milestone
Projects
Clear projects
No projects
Assignees
adam (Adam Melkus)
Clear assignees
No Assignees
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: starred/WireMock.Net-wiremock#618
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Originally created by @ArcaneTSGK on GitHub (Jul 24, 2024).
Originally assigned to: @StefH on GitHub.
When writing a response builder with
google.protobuf.Emptythe mock gRPC client will returnStatusCode=Unimplemented.Expected behavior:
It should be possible to use googles 'WellKnown' types as the protobuf body in the response builder.
Test to reproduce
I have tried with and without the
.WithTransformer(), I have also tried withnew Empty()new Empty {}andnew()but none of those match.Other related info
I am able to get the tests to work if the response is a type that I create in my proto, for example lets say that the HelloReply is in the proto file with a
message HelloReply { string reply_message = 1; }I have also tried creating my own
message EmptyResponse { }and this also did not workIt only works when the response contains something like
I have also tried creating my own
message EmptyResponse { string status = 1; }Please can someone either point me in the direction of what I am doing wrong to match an empty response, or confirm that this is a bug
Thanks
@StefH commented on GitHub (Jul 24, 2024):
@ArcaneTSGK Thanks for noticing this. This is a new scenario I never tested.
Probably I need to fix this here: https://github.com/StefH/ProtoBufJsonConverter/issues/15
I'll keep you informed on the progress...
@StefH commented on GitHub (Jul 29, 2024):
@ArcaneTSGK
I was thinking, are there any other predefined types in google?
And what should actually be the behavior of WireMock.Net if a google.protobuf.Empty is a return value?
Is this just an empty response?
@ArcaneTSGK commented on GitHub (Jul 29, 2024):
@StefH There are a number of them yes,
For Empty return value it's
Empty {}it's because protobuf does not allow you to request/response with null / no body like a typical REST API would.Converting Empty to JSON would represent an empty JSON object {}
Here are all of Googles Well Known types:
https://protobuf.dev/reference/protobuf/google.protobuf/
https://protobuf.dev/reference/protobuf/google.protobuf/#empty
Returning any of the scalar types in protobuf within a custom response that maps to a C# type is fine except for 'Enum'. I've not tried the 'Any' well-known type as my application doesn't have use for it, but I imagine that one might cause some issues, also when working with nullable types you use 'OneOf', again I haven't had to use these so I do not know if they'll work, but this is what a proto file would look like using those:
Usage of 'Any'
In that example a care give can be any pre-defined message in the proto, which could be Owner or the Foster, so that might be a test case for Wiremock to see if Any maps back, and lastly OneOf for nullables where you'd need to be able to allow a null return in the response:
And this is OneOf
@StefH commented on GitHub (Jul 30, 2024):
Currently I only have an easy way to support:
@StefH commented on GitHub (Aug 4, 2024):
https://github.com/StefH/ProtoBufJsonConverter/pull/18
@StefH commented on GitHub (Aug 4, 2024):
@ArcaneTSGK
If you have time, you can use this preview version: 1.5.62-ci-19066
@StefH commented on GitHub (Aug 15, 2024):
@ArcaneTSGK
Can you please test preview 1.5.62-ci-19067 , this version supports:
oneof@ArcaneTSGK commented on GitHub (Aug 15, 2024):
I will have some time tomorrow to take a look, I'll let you know my results, thanks @StefH
@StefH commented on GitHub (Aug 22, 2024):
@ArcaneTSGK
Did you have some time to check?
@StefH commented on GitHub (Aug 27, 2024):
@ArcaneTSGK
Did you have some time to check?
@ArcaneTSGK commented on GitHub (Aug 31, 2024):
Hi @StefH sorry for the delay,
Unfortunately, I can't install your prerelease version 1.5.62-ci-19067 as it does not resolve, are your pre-releases publicly available?
I only have the option (with prereleases enabled) to install 1.5.62 or 1.60 / 1.61
@StefH commented on GitHub (Aug 31, 2024):
Preview versions are defined on MyGet.
See https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions
But it could be that that specific version is automatically deleted because only x versions are kept on MyGet.
I will take a look and maybe I need to build a new preview.
@ArcaneTSGK commented on GitHub (Aug 31, 2024):
No worries, I've added MyGet as a feed and will await the specific version with the gRPC fix to test
@StefH commented on GitHub (Aug 31, 2024):
@ArcaneTSGK
Preview version on MyGet for this fix should be :
1.6.1-ci-19109@ArcaneTSGK commented on GitHub (Sep 2, 2024):
@StefH
So I attempted to use this build and I get the following exception:
(Status(StatusCode="Internal", Detail="Failed to deserialize response message.")
The proto file looks like this
The test is setup as follows:
I did try Duration and Timestamp aswell but those were returning unimplemented for me when I was using
google.protobuf.Timestampandgoogle.protobuf.Durationrespectively as return typesLet me know if I'm missing anything
I also tried the fully qualified name of Google.Protobuf.WellKnownTypes.Empty as the message type to no avail.
Thanks
@StefH commented on GitHub (Sep 2, 2024):
Strange, I did add a unit test https://github.com/WireMock-Net/WireMock.Net/blob/bug/1144-protobuf/test/WireMock.Net.Tests/Grpc/WireMockServerTests.Grpc.cs#L104
proto
Unit test code:
What is the difference?
@StefH commented on GitHub (Sep 2, 2024):
Also added another test: https://github.com/WireMock-Net/WireMock.Net/blob/bug/1144-protobuf/test/WireMock.Net.Tests/Grpc/WireMockServerTests.Grpc.cs#L144
@ArcaneTSGK commented on GitHub (Sep 3, 2024):
I will have to provide a minimal reproduction solution when I have time, I've tried a few different things and for .Empty I always get the unable to deserialize response, and for duration/timestamp I'm getting the Unimplemented error.
I'll provide a link to the repository and throw something together by the end of the week
@StefH commented on GitHub (Sep 5, 2024):
https://github.com/WireMock-Net/WireMock.Net/issues/1153
@StefH commented on GitHub (Sep 5, 2024):
Using https://protobuf.heyenrath.nl/ with your message and
google.protobuf.Emptydoes return an empty byte array@StefH commented on GitHub (Sep 11, 2024):
Hello @ArcaneTSGK, could you make an example project to demonstrate this issue?
@StefH commented on GitHub (Sep 17, 2024):
Hello @ArcaneTSGK, could you make an example project to demonstrate this issue?
@carlos-pilao-deltatre commented on GitHub (Sep 19, 2024):
Hello,
Just confirmed the reported issue (using the latest version: 1.6.3):
cc @StefH
@StefH commented on GitHub (Sep 20, 2024):
@carlos-pilao-deltatre
Can you please test preview version 1.6.2-ci-19188?
@carlos-pilao-deltatre commented on GitHub (Sep 20, 2024):
@StefH
Cannot find that release anymore. Tried with the latest preview (1.6.3-ci-19196) and cant compile my solution with that one:
@StefH commented on GitHub (Sep 20, 2024):
You did check MyGet?
@carlos-pilao-deltatre commented on GitHub (Sep 20, 2024):
yes
@StefH commented on GitHub (Sep 22, 2024):
@carlos-pilao-deltatre
try this
1.6.3-ci-19198
@carlos-pilao-deltatre commented on GitHub (Sep 23, 2024):
Getting the same issue...
@StefH
@StefH commented on GitHub (Sep 23, 2024):
1 and 3 are fixed. See preview version:
1.6.3-ci-19205
@StefH commented on GitHub (Sep 26, 2024):
Hello @carlos-pilao-deltatre / @ArcaneTSGK ; did you have time to validate that latest preview version?
@samir-babachikj-deltatre commented on GitHub (Oct 9, 2024):
Hello @StefH ,
The preview version '1.6.3-ci-19205' is currently unavailable.
@StefH commented on GitHub (Oct 9, 2024):
@samir-babachikj-deltatre
@ArcaneTSGK
@carlos-pilao-deltatre
You can use version
1.6.6-ci-19355.Preview versions are defined on MyGet.
See https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions
@samir-babachikj-deltatre commented on GitHub (Oct 10, 2024):
@StefH I only have these versions available:

@StefH commented on GitHub (Oct 12, 2024):
@samir-babachikj-deltatre
Use this version
1.6.6-ci-19363
@samir-babachikj-deltatre commented on GitHub (Oct 12, 2024):
@StefH The version you mentioned depends on: WireMock.Net.Abstractions 1.6.6-ci-19363, WireMock.Net.OpenApiParser 1.6.6-ci-19363 and WireMock.Org.Abstractions 1.6.6-ci-19363.
Due this reason, I am getting the NU1603 warning (ref. https://learn.microsoft.com/en-us/nuget/reference/errors-and-warnings/nu1603), thus it was resolving it to 1.6.6 stable. I instructed my project not to treat this warning as error, which would then result with an exception with the following message: "System.TypeLoadException : Could not load type 'WireMock.Models.IdOrTexts' from assembly 'WireMock.Net.Abstractions, Version=1.6.6.0, Culture=neutral, PublicKeyToken=c8d65537854e1f03'." Making me unable to properly test it.
@StefH commented on GitHub (Oct 12, 2024):
I deleted all packages from MyGet and ran a new build.
Now only 1.6.6-ci-19365 should be there.
@samir-babachikj-deltatre commented on GitHub (Oct 14, 2024):
@StefH Tried now, and at least for
3. If you have _import google/protobuf/struct.proto_ in your proto file then the response will be always _404 Unimplemented_, I can confirm that the problem still persists.
@StefH commented on GitHub (Oct 14, 2024):
That's very strange.
Using
import "google/protobuf/empty.proto";or
import "google/protobuf/struct.proto";Will actually be the same logic, both are well defined google elements.
Using this proto:
In https://protobuf.heyenrath.nl/

Will just work fine:
Can you please provide your .proto file? which has an issue ?
@samir-babachikj-deltatre commented on GitHub (Oct 14, 2024):
@StefH The problem is the use of the Value type defined inside the struct.proto (ref. https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/struct.proto).
I see you are using NullValue, but it is an enum, so if you enrich your message with the use of google.protobuf.Value type, then the issue appears.
@StefH commented on GitHub (Oct 14, 2024):
Can you try 1.6.6-ci-19366 ?
@samir-babachikj-deltatre commented on GitHub (Oct 15, 2024):
@StefH It works now. Thank you!
@samir-babachikj-deltatre commented on GitHub (Oct 16, 2024):
Hi @StefH ,
currently I am encountering a different issue.
It is not throwing exceptions now, but I am not able to mock the struct.Value field.
I am trying to mock it to ExpandoObject, but I am not having success with it, as it returns null always.
Can you please check that?
@StefH commented on GitHub (Oct 16, 2024):
Yes, I think I made a mistake in that Value or Struct. I'll take a look.
@StefH commented on GitHub (Oct 17, 2024):
@samir-babachikj-deltatre
if possible, can you provide the code / protobuf you are using?
@StefH commented on GitHub (Oct 17, 2024):
@samir-babachikj-deltatre
Can you try 1.6.6-ci-19385 ?
note that you need to use a Value this:
@samir-babachikj-deltatre commented on GitHub (Oct 17, 2024):
@StefH It is working as expected now! Thank you🙏
@StefH commented on GitHub (Oct 17, 2024):
https://github.com/WireMock-Net/WireMock.Net/pull/1198
@carlos-pilao-deltatre commented on GitHub (Nov 17, 2024):
@StefH the original issue of this thread still happening: if you have a service returning an empty response you cannot mock it. Tried several approaches like @ArcaneTSGK did without success. The only way I found so far is to create a custom response like VoidResponse and I need to have a field at least on it because if I return a structure without fields it will not work either :(
@ArcaneTSGK did you find any solution for this?
@StefH commented on GitHub (Nov 17, 2024):
It should work correctly.
Can you please create a new issue with example code?