WithProxy(...) does not save the mappings to file #317

Closed
opened 2025-12-29 08:26:00 +01:00 by adam · 18 comments
Owner

Originally created by @martinkra on GitHub (Dec 5, 2020).

Originally assigned to: @StefH on GitHub.

I've created a console app that runs the server trying to record/capture mappings:

var server = WireMock.Server.WireMockServer.Start(new WireMockServerSettings
{
    Port = 1234,
    StartAdminInterface = true,
    ProxyAndRecordSettings = new ProxyAndRecordSettings
    {
        SaveMapping = true,
        SaveMappingToFile = true
    }
}); ;

server
    .Given(Request.Create().UsingGet())
    .RespondWith(Response.Create()
        .WithProxy(new ProxyAndRecordSettings
        {
            Url = "https://github.com/",
            SaveMapping = true,
            SaveMappingToFile = true
        }));

Console.WriteLine("Press any key to stop the server");
Console.ReadLine();

The server works fine, e.g. when accessing localhost:1234/test1 I get the data from https://github.com/test1. The problem is that I am unable to find the way to get the recorded mapping... No files are created. What am I missing?

Originally created by @martinkra on GitHub (Dec 5, 2020). Originally assigned to: @StefH on GitHub. I've created a console app that runs the server trying to record/capture mappings: ``` c# var server = WireMock.Server.WireMockServer.Start(new WireMockServerSettings { Port = 1234, StartAdminInterface = true, ProxyAndRecordSettings = new ProxyAndRecordSettings { SaveMapping = true, SaveMappingToFile = true } }); ; server .Given(Request.Create().UsingGet()) .RespondWith(Response.Create() .WithProxy(new ProxyAndRecordSettings { Url = "https://github.com/", SaveMapping = true, SaveMappingToFile = true })); Console.WriteLine("Press any key to stop the server"); Console.ReadLine(); ``` The server works fine, e.g. when accessing localhost:1234/test1 I get the data from https://github.com/test1. The problem is that I am unable to find the way to get the recorded mapping... No files are created. What am I missing?
adam added the bug label 2025-12-29 08:26:00 +01:00
adam closed this issue 2025-12-29 08:26:00 +01:00
Author
Owner

@StefH commented on GitHub (Dec 5, 2020):

Files are created in the folder {framework}/__admin/mappings.

This folder is located in the same place where the binaries are located:
image

@StefH commented on GitHub (Dec 5, 2020): Files are created in the folder `{framework}/__admin/mappings`. This folder is located in the same place where the binaries are located: ![image](https://user-images.githubusercontent.com/249938/101246953-c80c7580-3716-11eb-802a-a4c20d168aec.png)
Author
Owner

@martinkra commented on GitHub (Dec 5, 2020):

In my case the folder is netcoreapp3.1/__admin mappings are not created.
image

I've tried with .Net Core 2.1, didn't help.
image

@martinkra commented on GitHub (Dec 5, 2020): In my case the folder is netcoreapp3.1/__admin mappings are not created. ![image](https://user-images.githubusercontent.com/5516508/101247592-c644b100-371a-11eb-89df-119576fb8596.png) I've tried with .Net Core 2.1, didn't help. ![image](https://user-images.githubusercontent.com/5516508/101247710-5682f600-371b-11eb-9c5d-5c1f63e38ca2.png)
Author
Owner

@StefH commented on GitHub (Dec 5, 2020):

Hello @martinkra, now I see that you are defining proxy settings in two places.

Try like this example: https://github.com/WireMock-Net/WireMock.Net/blob/master/examples/WireMock.Net.Console.Proxy.NETCoreApp2/Program.cs

@StefH commented on GitHub (Dec 5, 2020): Hello @martinkra, now I see that you are defining proxy settings in two places. Try like this example: https://github.com/WireMock-Net/WireMock.Net/blob/master/examples/WireMock.Net.Console.Proxy.NETCoreApp2/Program.cs
Author
Owner

@martinkra commented on GitHub (Dec 5, 2020):

Your hint 'defining proxy settings in two places' helped, example too, thank you.

I figured that the problem was with defining proxy settings for a specific request. Recording settings seem to work only when configured during server start and should not be touched later. The code that works:

            var server = WireMock.Server.WireMockServer.Start(new WireMockServerSettings
            {
                Port = 1234,
                StartAdminInterface = true,
                ProxyAndRecordSettings = new ProxyAndRecordSettings
                {
                    Url = "http://postman-echo.com/post",
                    SaveMapping = true,
                    SaveMappingToFile = true
                }
            });

            Console.WriteLine("Press any key to stop the server");
            Console.ReadLine();

            server.Stop();

API makes appear that it is possible to configure recording for a specific request but that does not work:

            // does not work, should work or not be possible to configure
            server
                .Given(Request.Create().UsingGet())
                .RespondWith(Response.Create()
                   .WithProxy(new ProxyAndRecordSettings
                   {
                       Url = "https://github.com/",
                       SaveMapping = true,
                       SaveMappingToFile = true
                   }));
@martinkra commented on GitHub (Dec 5, 2020): Your hint 'defining proxy settings in two places' helped, example too, thank you. I figured that the problem was with defining proxy settings for a specific request. Recording settings seem to work only when configured during server start and should not be touched later. The code that works: ```C# var server = WireMock.Server.WireMockServer.Start(new WireMockServerSettings { Port = 1234, StartAdminInterface = true, ProxyAndRecordSettings = new ProxyAndRecordSettings { Url = "http://postman-echo.com/post", SaveMapping = true, SaveMappingToFile = true } }); Console.WriteLine("Press any key to stop the server"); Console.ReadLine(); server.Stop(); ``` API makes appear that it is possible to configure recording for a specific request but that does not work: ```C# // does not work, should work or not be possible to configure server .Given(Request.Create().UsingGet()) .RespondWith(Response.Create() .WithProxy(new ProxyAndRecordSettings { Url = "https://github.com/", SaveMapping = true, SaveMappingToFile = true })); ```
Author
Owner

@StefH commented on GitHub (Dec 6, 2020):

@martinkra I see you point. I'll check if I can change the code to save the mapping in all scenarios.

@StefH commented on GitHub (Dec 6, 2020): @martinkra I see you point. I'll check if I can change the code to save the mapping in all scenarios.
Author
Owner

@StefH commented on GitHub (Dec 6, 2020):

https://github.com/WireMock-Net/WireMock.Net/pull/550

@StefH commented on GitHub (Dec 6, 2020): https://github.com/WireMock-Net/WireMock.Net/pull/550
Author
Owner

@martinkra commented on GitHub (Dec 7, 2020):

I couldn't find 1.3.8-ci-14324 on MyGet/stefh...

[cid:9ce639bc-24ce-4f15-8bd7-00b973d03bc4]


From: Stef Heyenrath notifications@github.com
Sent: Sunday, December 6, 2020 12:13 PM
To: WireMock-Net/WireMock.Net WireMock.Net@noreply.github.com
Cc: martinkra martinkra@gmail.com; Mention mention@noreply.github.com
Subject: Re: [WireMock-Net/WireMock.Net] How to setup proxy and recording properly (#549)

Can you try NuGet version 1.3.8-ci-14324 from MyGet?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com/WireMock-Net/WireMock.Net/issues/549#issuecomment-739494206, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABKCZXC42A6CHL67JXUECYDSTNYNRANCNFSM4UORQK5A.

@martinkra commented on GitHub (Dec 7, 2020): I couldn't find 1.3.8-ci-14324 on MyGet/stefh... [cid:9ce639bc-24ce-4f15-8bd7-00b973d03bc4] ________________________________ From: Stef Heyenrath <notifications@github.com> Sent: Sunday, December 6, 2020 12:13 PM To: WireMock-Net/WireMock.Net <WireMock.Net@noreply.github.com> Cc: martinkra <martinkra@gmail.com>; Mention <mention@noreply.github.com> Subject: Re: [WireMock-Net/WireMock.Net] How to setup proxy and recording properly (#549) Can you try NuGet version 1.3.8-ci-14324 from MyGet? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub<https://github.com/WireMock-Net/WireMock.Net/issues/549#issuecomment-739494206>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ABKCZXC42A6CHL67JXUECYDSTNYNRANCNFSM4UORQK5A>.
Author
Owner

@StefH commented on GitHub (Dec 7, 2020):

@martinkra
Sorry, the version you need is 1.3.8-ci-14327

@StefH commented on GitHub (Dec 7, 2020): @martinkra Sorry, the version you need is `1.3.8-ci-14327`
Author
Owner

@martinkra commented on GitHub (Dec 7, 2020):

No such version on nuget.org, MyGet feed https://www.myget.org/F/stefh does no longer work for me.

@martinkra commented on GitHub (Dec 7, 2020): No such version on nuget.org, MyGet feed https://www.myget.org/F/stefh does no longer work for me.
Author
Owner
@StefH commented on GitHub (Dec 7, 2020): Feed should be: https://www.myget.org/F/wiremock-net/api/v3/index.json See also https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions
Author
Owner

@martinkra commented on GitHub (Dec 7, 2020):

I've found the feed and the version. In build 1.3.8-ci-14327 recording settings on request level do not break the recording:

            var server = WireMock.Server.WireMockServer.Start(new WireMockServerSettings
            {
                Port = 1234,
                StartAdminInterface = true,
                ProxyAndRecordSettings = new ProxyAndRecordSettings
                {
                    Url = "http://postman-echo.com/post",
                    SaveMapping = true,
                    SaveMappingToFile = true
                }
            });

            server
                .Given(Request.Create().UsingGet())
                .RespondWith(Response.Create()
                   .WithProxy(new ProxyAndRecordSettings
                   {
                       Url = "http://postman-echo.com/post",
                       SaveMapping = true,
                       SaveMappingToFile = true
                   }));

            Console.WriteLine("Press any key to stop the server");
            Console.ReadLine();

            server.Stop();

However, it is still a bit confusing that one could configure request level recording whithout setting up global recording, it would not work in that scenario.

            var server = WireMock.Server.WireMockServer.Start(new WireMockServerSettings
            {
                Port = 1234,
                StartAdminInterface = true //,
                //ProxyAndRecordSettings = new ProxyAndRecordSettings
                //{
                //    Url = "http://postman-echo.com/post",
                //    SaveMapping = true,
                //    SaveMappingToFile = true
                //}
            });

            server
                .Given(Request.Create().UsingGet())
                .RespondWith(Response.Create()
                   .WithProxy(new ProxyAndRecordSettings
                   {
                       Url = "http://postman-echo.com/post",
                       SaveMapping = true,
                       SaveMappingToFile = true
                   }));

@martinkra commented on GitHub (Dec 7, 2020): I've found the feed and the version. In build 1.3.8-ci-14327 recording settings on request level do not break the recording: ```C# var server = WireMock.Server.WireMockServer.Start(new WireMockServerSettings { Port = 1234, StartAdminInterface = true, ProxyAndRecordSettings = new ProxyAndRecordSettings { Url = "http://postman-echo.com/post", SaveMapping = true, SaveMappingToFile = true } }); server .Given(Request.Create().UsingGet()) .RespondWith(Response.Create() .WithProxy(new ProxyAndRecordSettings { Url = "http://postman-echo.com/post", SaveMapping = true, SaveMappingToFile = true })); Console.WriteLine("Press any key to stop the server"); Console.ReadLine(); server.Stop(); ``` However, it is still a bit confusing that one could configure request level recording whithout setting up global recording, it would not work in that scenario. ```C# var server = WireMock.Server.WireMockServer.Start(new WireMockServerSettings { Port = 1234, StartAdminInterface = true //, //ProxyAndRecordSettings = new ProxyAndRecordSettings //{ // Url = "http://postman-echo.com/post", // SaveMapping = true, // SaveMappingToFile = true //} }); server .Given(Request.Create().UsingGet()) .RespondWith(Response.Create() .WithProxy(new ProxyAndRecordSettings { Url = "http://postman-echo.com/post", SaveMapping = true, SaveMappingToFile = true })); ```
Author
Owner

@StefH commented on GitHub (Dec 7, 2020):

My intention was to fix the code so that your last code example would work fine. If this code example does not work correctly, I need to check the code again.

@StefH commented on GitHub (Dec 7, 2020): My intention was to fix the code so that your last code example would work fine. If this code example does not work correctly, I need to check the code again.
Author
Owner

@martinkra commented on GitHub (Dec 7, 2020):

Code where recording is set twice works in 1.3.8-ci-14327, that did not work before so the original issue is fixed.

Code where recording is not set during server start and is set on request level (second snippet in my previous comment) does not work. I can manage without that feature but thought it is worth noting that it appears as an inconsistency or a bug.

@martinkra commented on GitHub (Dec 7, 2020): Code where recording is set twice works in 1.3.8-ci-14327, that did not work before so the original issue is fixed. Code where recording is not set during server start and is set on request level (second snippet in my previous comment) does not work. I can manage without that feature but thought it is worth noting that it appears as an inconsistency or a bug.
Author
Owner

@StefH commented on GitHub (Dec 7, 2020):

New (1.3.8-ci-14337) on MyGet

  1. If WireMockServerSettings.ProxyAndRecordSettings is defined, the SaveMapping value is used, also for WithProxy
  2. If WireMockServerSettings.ProxyAndRecordSettings is not defined,but the ProxyAndRecordSettings.SaveMapping is set top true, then from WithProxy is used

I think this is the full solution.

@StefH commented on GitHub (Dec 7, 2020): New (`1.3.8-ci-14337`) on MyGet 1. If WireMockServerSettings.ProxyAndRecordSettings is defined, the SaveMapping value is used, also for WithProxy 2. If WireMockServerSettings.ProxyAndRecordSettings is **not** defined,but the ProxyAndRecordSettings.SaveMapping is set top true, then from WithProxy is used I think this is the full solution.
Author
Owner

@martinkra commented on GitHub (Dec 7, 2020):

I agree that the proposed is the full solution. However, 1.3.8-ci-14337 does not work as described. The following code does not record mappings:

            var server = WireMock.Server.WireMockServer.Start(new WireMockServerSettings
            {
                Port = 1234,
                StartAdminInterface = true
            });

            server
                .Given(Request.Create().UsingGet())
                .RespondWith(Response.Create()
                   .WithProxy(new ProxyAndRecordSettings
                   {
                       Url = "http://postman-echo.com/post",
                       SaveMapping = true,
                       SaveMappingToFile = true
                   }));
@martinkra commented on GitHub (Dec 7, 2020): I agree that the proposed is the full solution. However, 1.3.8-ci-14337 does not work as described. The following code does not record mappings: ```C# var server = WireMock.Server.WireMockServer.Start(new WireMockServerSettings { Port = 1234, StartAdminInterface = true }); server .Given(Request.Create().UsingGet()) .RespondWith(Response.Create() .WithProxy(new ProxyAndRecordSettings { Url = "http://postman-echo.com/post", SaveMapping = true, SaveMappingToFile = true })); ```
Author
Owner

@StefH commented on GitHub (Dec 7, 2020):

@martinkra Thank you for your testing.

I hope this version 1.3.8-ci-14339 works as defined.

@StefH commented on GitHub (Dec 7, 2020): @martinkra Thank you for your testing. I hope this version `1.3.8-ci-14339` works as defined.
Author
Owner

@martinkra commented on GitHub (Dec 7, 2020):

@StefH Thank you for your help and fixes.

Version 1.3.8-ci-14339 works as defined.

@martinkra commented on GitHub (Dec 7, 2020): @StefH Thank you for your help and fixes. Version 1.3.8-ci-14339 works as defined.
Author
Owner

@StefH commented on GitHub (Dec 8, 2020):

New official version will be released today.

@StefH commented on GitHub (Dec 8, 2020): New official version will be released today.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#317