How to connect to wiremock server instance to add mappings? #334

Closed
opened 2025-12-29 15:21:10 +01:00 by adam · 4 comments
Owner

Originally created by @mcopjan on GitHub (Feb 24, 2021).

Originally assigned to: @StefH on GitHub.

Hi, I am new to WireMock and trying to do some mocking for grpc service using https://github.com/Adven27/grpc-wiremock

I have a wiremock server running on localhost:8888, if I hit http://localhost:8888/__admin/mappings from my browser I can see there are no mappings

{
  "mappings" : [ ],
  "meta" : {
    "total" : 0
  }
}

I would like to add some mappings now so I am using the following code (first I am trying to fetch existing mappings expecting an empty list)

[Test]
        public async Task Test1()
        {
            // Create an implementation of the IWireMockAdminApi and pass in the base URL for the API.
            var api = RestClient.For<IWireMockAdminApi>("http://localhost:8888");

            var mappings = await api.GetMappingsAsync();
            Console.WriteLine($"mappings = {JsonConvert.SerializeObject(mappings)}");
        }

The above code fails on

Newtonsoft.Json.JsonSerializationException : Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.IList`1[WireMock.Admin.Mappings.MappingModel]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
Path 'mappings', line 2, position 14.

   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
   at RestEase.JsonResponseDeserializer.Deserialize[T](String content, HttpResponseMessage response, ResponseDeserializerInfo info)
   at RestEase.Implementation.Requester.Deserialize[T](String content, HttpResponseMessage response, IRequestInfo requestInfo)
   at RestEase.Implementation.Requester.RequestAsync[T](IRequestInfo requestInfo)
   at WireMockTest.Tests.Setup() in /Users/martinco/Work/WireMockTest/WireMockTest/WireMockTest/UnitTest1.cs:line 26
   at NUnit.Framework.Internal.TaskAwaitAdapter.GenericAdapter`1.BlockUntilCompleted()
   at NUnit.Framework.Internal.MessagePumpStrategy.NoMessagePumpStrategy.WaitForCompletion(AwaitAdapter awaitable)
   at NUnit.Framework.Internal.AsyncToSyncAdapter.Await(Func`1 invoke)
   at NUnit.Framework.Internal.Commands.SetUpTearDownItem.RunSetUpOrTearDownMethod(TestExecutionContext context, MethodInfo method)
   at NUnit.Framework.Internal.Commands.SetUpTearDownItem.RunSetUp(TestExecutionContext context)
   at NUnit.Framework.Internal.Commands.SetUpTearDownCommand.<>c__DisplayClass0_0.<.ctor>b__0(TestExecutionContext context)
   at NUnit.Framework.Internal.Commands.BeforeAndAfterTestCommand.<>c__DisplayClass1_0.<Execute>b__0()
   at NUnit.Framework.Internal.Commands.BeforeAndAfterTestCommand.RunTestMethodInThreadAbortSafeZone(TestExecutionContext context, Action action)

csproj details

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>

    <IsPackable>false</IsPackable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="NUnit" Version="3.12.0" />
    <PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
    <PackageReference Include="WireMock.Net.RestClient" Version="1.4.5" />
    <PackageReference Include="WireMock.Net.Abstractions" Version="1.4.5" />
  </ItemGroup>

</Project>

I tried other methods such as GetSettingsAsync() with the same result.
What I am missing here please?

Originally created by @mcopjan on GitHub (Feb 24, 2021). Originally assigned to: @StefH on GitHub. Hi, I am new to WireMock and trying to do some mocking for grpc service using https://github.com/Adven27/grpc-wiremock I have a wiremock server running on localhost:8888, if I hit http://localhost:8888/__admin/mappings from my browser I can see there are no mappings ``` json { "mappings" : [ ], "meta" : { "total" : 0 } } ``` I would like to add some mappings now so I am using the following code (first I am trying to fetch existing mappings expecting an empty list) ``` c# [Test] public async Task Test1() { // Create an implementation of the IWireMockAdminApi and pass in the base URL for the API. var api = RestClient.For<IWireMockAdminApi>("http://localhost:8888"); var mappings = await api.GetMappingsAsync(); Console.WriteLine($"mappings = {JsonConvert.SerializeObject(mappings)}"); } ``` The above code fails on ``` Newtonsoft.Json.JsonSerializationException : Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.IList`1[WireMock.Admin.Mappings.MappingModel]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly. To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object. Path 'mappings', line 2, position 14. at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings) at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings) at RestEase.JsonResponseDeserializer.Deserialize[T](String content, HttpResponseMessage response, ResponseDeserializerInfo info) at RestEase.Implementation.Requester.Deserialize[T](String content, HttpResponseMessage response, IRequestInfo requestInfo) at RestEase.Implementation.Requester.RequestAsync[T](IRequestInfo requestInfo) at WireMockTest.Tests.Setup() in /Users/martinco/Work/WireMockTest/WireMockTest/WireMockTest/UnitTest1.cs:line 26 at NUnit.Framework.Internal.TaskAwaitAdapter.GenericAdapter`1.BlockUntilCompleted() at NUnit.Framework.Internal.MessagePumpStrategy.NoMessagePumpStrategy.WaitForCompletion(AwaitAdapter awaitable) at NUnit.Framework.Internal.AsyncToSyncAdapter.Await(Func`1 invoke) at NUnit.Framework.Internal.Commands.SetUpTearDownItem.RunSetUpOrTearDownMethod(TestExecutionContext context, MethodInfo method) at NUnit.Framework.Internal.Commands.SetUpTearDownItem.RunSetUp(TestExecutionContext context) at NUnit.Framework.Internal.Commands.SetUpTearDownCommand.<>c__DisplayClass0_0.<.ctor>b__0(TestExecutionContext context) at NUnit.Framework.Internal.Commands.BeforeAndAfterTestCommand.<>c__DisplayClass1_0.<Execute>b__0() at NUnit.Framework.Internal.Commands.BeforeAndAfterTestCommand.RunTestMethodInThreadAbortSafeZone(TestExecutionContext context, Action action) ``` csproj details ``` <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netcoreapp3.1</TargetFramework> <IsPackable>false</IsPackable> </PropertyGroup> <ItemGroup> <PackageReference Include="NUnit" Version="3.12.0" /> <PackageReference Include="NUnit3TestAdapter" Version="3.16.1" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" /> <PackageReference Include="WireMock.Net.RestClient" Version="1.4.5" /> <PackageReference Include="WireMock.Net.Abstractions" Version="1.4.5" /> </ItemGroup> </Project> ``` I tried other methods such as GetSettingsAsync() with the same result. What I am missing here please?
adam added the question label 2025-12-29 15:21:10 +01:00
adam closed this issue 2025-12-29 15:21:10 +01:00
Author
Owner

@StefH commented on GitHub (Feb 24, 2021):

Hello @mcopjan,

I see your confusion.

The issue is that you are running the Java version from WireMock and trying to connect to this running Java instance using the Client Libraries from WireMock.Net (this project).

This will not work because the mappings are not compatible (sorry for that) --> https://github.com/WireMock-Net/WireMock.Net/issues/491.

@StefH commented on GitHub (Feb 24, 2021): Hello @mcopjan, I see your confusion. The issue is that you are running the **Java** version from [WireMock](http://wiremock.org/) and trying to connect to this running Java instance using the Client Libraries from WireMock.Net (this project). This will not work because the mappings are not compatible (sorry for that) --> https://github.com/WireMock-Net/WireMock.Net/issues/491.
Author
Owner

@mcopjan commented on GitHub (Feb 24, 2021):

hi @StefH, thanks for your quick answer. That's unfortunate. I would expect the client communication with the Java server works no matter what language of client I am using (as long as I meet the API contract of server)

@mcopjan commented on GitHub (Feb 24, 2021): hi @StefH, thanks for your quick answer. That's unfortunate. I would expect the client communication with the Java server works no matter what language of client I am using (as long as I meet the API contract of server)
Author
Owner

@StefH commented on GitHub (Feb 24, 2021):

The API contract from WireMock Java and this project WireMock.Net is not compatible. (The ideas are the same, but the mappings are different.)

This .NET Client can only be used for this project : WireMock.Net

However, if you want to connect using a C# Client to WireMock Java, you could try to load the Swagger from the Java project (http://wiremock.org/docs/api/) and generate the c# client + models using this project: https://github.com/StefH/RestEase-Client-Generator

@StefH commented on GitHub (Feb 24, 2021): The API contract from WireMock Java and this project WireMock.Net is not compatible. (The ideas are the same, but the mappings are different.) This .NET Client can only be used for this project : WireMock.Net However, if you want to connect using a C# Client to WireMock Java, you could try to load the Swagger from the Java project (http://wiremock.org/docs/api/) and generate the c# client + models using this project: https://github.com/StefH/RestEase-Client-Generator
Author
Owner

@StefH commented on GitHub (Dec 29, 2023):

See also
https://github.com/WireMock-Net/WireMock.Net/discussions/1045

@StefH commented on GitHub (Dec 29, 2023): See also https://github.com/WireMock-Net/WireMock.Net/discussions/1045
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#334