Static Mappings present in server but the request returns 404 #533

Closed
opened 2025-12-29 15:26:05 +01:00 by adam · 1 comment
Owner

Originally created by @dariooo512 on GitHub (Jul 21, 2023).

Describe the bug

I can't figure out how to make ReadStaticMappings work.
After calling ReadStaticMappings and verifying the server has mappings in the server.Mappings array, the following request yields 404.

Expected behavior:

After adding autogenerated mappings the server should return the body found in the json

Test to reproduce

Download and run this sample
Program.zip

OR

  • 1 Create a .net7 console app
  • 2 Paste the code
using WireMock.Server;

Console.WriteLine("Hello, World!");
var server = WireMockServer.Start();
server.ReadStaticMappings(Directory.GetCurrentDirectory());

if (!server.Mappings.Any())
{
    throw new Exception("No mappings found");
}

var client = server.CreateClient();
var response = await client.GetAsync($"{client.BaseAddress}manageToken/getToken?Key=key&Secret=secret");

response.EnsureSuccessStatusCode();

var content = await response.Content.ReadAsStringAsync();

Console.WriteLine(content);
  • 3 add the following stub next to the program.cs with name managetoken_gettoken-f14d4844-a3e0-4130-a830-03f71a7cdbe8.json
{
  "id" : "f14d4844-a3e0-4130-a830-03f71a7cdbe8",
  "name" : "managetoken_gettoken",
  "request" : {
    "url" : "/manageToken/getToken?Key=key&Secret=secret",
    "method" : "GET"
  },
  "response" : {
    "status" : 200,
    "body" : "{\"access_token\":\"token\",\"scope\":\"device_383334.0\",\"token_type\":\"Bearer\",\"expires_in\":3600}",
    "headers" : {
      "X-Frame-Options" : "DENY",
      "activityid" : "782ee60c-a48c-4d64-b9b3-8f99649df207",
      "Access-Control-Expose-Headers" : "",
      "Cache-Control" : "no-store",
      "Access-Control-Allow-Origin" : "*",
      "Access-Control-Allow-Methods" : "GET",
      "uber-trace-id" : "df44af849f44bab6%3Acccf9a31b54cfa0d%3A2d2865c70c60927b%3A1",
      "X-Content-Type-Options" : "nosniff",
      "Pragma" : "no-cache",
      "X-XSS-Protection" : "1; mode=block",
      "Access-Control-Allow-Headers" : "content-type",
      "Content-Type" : "application/json",
      "Date" : "Fri, 21 Jul 2023 15:08:55 GMT"
    }
  },
  "uuid" : "f14d4844-a3e0-4130-a830-03f71a7cdbe8",
  "persistent" : true,
  "insertionIndex" : 1
}

-4 set the Property of this file 'Copy to output directory' to 'Copy if newer'
-5 Run the program

The Stub was generated using Wiremock docker wiremock/wiremock:latest

Originally created by @dariooo512 on GitHub (Jul 21, 2023). ### Describe the bug I can't figure out how to make ReadStaticMappings work. After calling ReadStaticMappings and verifying the server has mappings in the server.Mappings array, the following request yields 404. ### Expected behavior: After adding autogenerated mappings the server should return the body found in the json ### Test to reproduce Download and run this sample [Program.zip](https://github.com/WireMock-Net/WireMock.Net/files/12130455/Program.zip) OR - 1 Create a .net7 console app - 2 Paste the code ``` using WireMock.Server; Console.WriteLine("Hello, World!"); var server = WireMockServer.Start(); server.ReadStaticMappings(Directory.GetCurrentDirectory()); if (!server.Mappings.Any()) { throw new Exception("No mappings found"); } var client = server.CreateClient(); var response = await client.GetAsync($"{client.BaseAddress}manageToken/getToken?Key=key&Secret=secret"); response.EnsureSuccessStatusCode(); var content = await response.Content.ReadAsStringAsync(); Console.WriteLine(content); ``` - 3 add the following stub next to the program.cs with name `managetoken_gettoken-f14d4844-a3e0-4130-a830-03f71a7cdbe8.json` ``` { "id" : "f14d4844-a3e0-4130-a830-03f71a7cdbe8", "name" : "managetoken_gettoken", "request" : { "url" : "/manageToken/getToken?Key=key&Secret=secret", "method" : "GET" }, "response" : { "status" : 200, "body" : "{\"access_token\":\"token\",\"scope\":\"device_383334.0\",\"token_type\":\"Bearer\",\"expires_in\":3600}", "headers" : { "X-Frame-Options" : "DENY", "activityid" : "782ee60c-a48c-4d64-b9b3-8f99649df207", "Access-Control-Expose-Headers" : "", "Cache-Control" : "no-store", "Access-Control-Allow-Origin" : "*", "Access-Control-Allow-Methods" : "GET", "uber-trace-id" : "df44af849f44bab6%3Acccf9a31b54cfa0d%3A2d2865c70c60927b%3A1", "X-Content-Type-Options" : "nosniff", "Pragma" : "no-cache", "X-XSS-Protection" : "1; mode=block", "Access-Control-Allow-Headers" : "content-type", "Content-Type" : "application/json", "Date" : "Fri, 21 Jul 2023 15:08:55 GMT" } }, "uuid" : "f14d4844-a3e0-4130-a830-03f71a7cdbe8", "persistent" : true, "insertionIndex" : 1 } ``` -4 set the Property of this file 'Copy to output directory' to 'Copy if newer' -5 Run the program ### Other related info The Stub was generated using Wiremock docker wiremock/wiremock:latest
adam added the question label 2025-12-29 15:26:05 +01:00
adam closed this issue 2025-12-29 15:26:05 +01:00
Author
Owner

@StefH commented on GitHub (Jul 21, 2023):

@dariooo512
Your mapping file looks like a WireMock.Org mapping file.

When reading static mappings, you need to use a WireMock.Net mapping file.

(There is limited in this project for using WireMock.Org mapping files.)

See

@StefH commented on GitHub (Jul 21, 2023): @dariooo512 Your mapping file looks like a WireMock.Org mapping file. When reading static mappings, you need to use a WireMock.Net mapping file. (There is limited in this project for using WireMock.Org mapping files.) See - https://github.com/WireMock-Net/WireMock.Net/wiki/Admin-API-Reference - https://github.com/WireMock-Net/WireMock.Net/wiki/WireMock.Org
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#533