Should my URL be replaced with 'localhost' #597

Closed
opened 2025-12-29 08:30:44 +01:00 by adam · 8 comments
Owner

Originally created by @domwvitality on GitHub (May 7, 2024).

Originally assigned to: @StefH on GitHub.

When I try and configure a my WireMockServer to start with a specific address it is overwritten when created and replaced with 'localhost'.

Service = WireMockServer.Start(new WireMockServerSettings
{
    Urls = new[] { "http://172.18.0.1:8102" }
});

The code above would create a new server with a URL of 'http://localhost:8102' instead of 'http://172.18.0.1:8102'

image

I noticed that version 1.1.10 is the last version which would set the URL to what I provided, anything after this replaced it with 'localhost'.

Is this expected behaviour?

Originally created by @domwvitality on GitHub (May 7, 2024). Originally assigned to: @StefH on GitHub. When I try and configure a my WireMockServer to start with a specific address it is overwritten when created and replaced with 'localhost'. ```c# Service = WireMockServer.Start(new WireMockServerSettings { Urls = new[] { "http://172.18.0.1:8102" } }); ``` The code above would create a new server with a URL of 'http://localhost:8102' instead of 'http://172.18.0.1:8102' ![image](https://github.com/WireMock-Net/WireMock.Net/assets/81167268/4c0b2a3e-0479-4790-a263-8056c0491dfa) I noticed that version 1.1.10 is the last version which would set the URL to what I provided, anything after this replaced it with 'localhost'. Is this expected behaviour?
adam added the question label 2025-12-29 08:30:44 +01:00
adam closed this issue 2025-12-29 08:30:44 +01:00
Author
Owner

@StefH commented on GitHub (May 7, 2024):

172.18.0.1 is your private local ip-address?

@StefH commented on GitHub (May 7, 2024): 172.18.0.1 is your private local ip-address?
Author
Owner

@domwvitality commented on GitHub (May 7, 2024):

Yeah, that's correct.
Docker is used to start various services we depend on and they get assigned this address and an available port number

@domwvitality commented on GitHub (May 7, 2024): Yeah, that's correct. Docker is used to start various services we depend on and they get assigned this address and an available port number
Author
Owner

@StefH commented on GitHub (May 7, 2024):

I understand. The logic has been changed indeed. I'll change the code in https://github.com/WireMock-Net/WireMock.Net/pull/1100

And if you want, you can test a preview version 1.5.52-ci-18499, see
https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions

@StefH commented on GitHub (May 7, 2024): I understand. The logic has been changed indeed. I'll change the code in https://github.com/WireMock-Net/WireMock.Net/pull/1100 And if you want, you can test a preview version `1.5.52-ci-18499`, see https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions
Author
Owner

@StefH commented on GitHub (May 13, 2024):

@domwvitality
Did you have time to test the preview version?

@StefH commented on GitHub (May 13, 2024): @domwvitality Did you have time to test the preview version?
Author
Owner

@domwvitality commented on GitHub (May 13, 2024):

@StefH
Sure, will try and get that tested and confirmed today.

@domwvitality commented on GitHub (May 13, 2024): @StefH Sure, will try and get that tested and confirmed today.
Author
Owner

@domwvitality commented on GitHub (May 16, 2024):

Hi @StefH ,

Apologies for the delay. I've just got round to testing that build and it fails for me when starting the server. I'm using the same snippet...

Service = WireMockServer.Start(new WireMockServerSettings
{
    Urls = new[] { "http://172.18.0.1:8102" }
});

but when I execute I get this error...

WireMock.Exceptions.WireMockException: Service start failed with error: One or more errors occurred. (Cannot assign requested address)
 ---> System.AggregateException: One or more errors occurred. (Cannot assign requested address)
 ---> System.Net.Sockets.SocketException (99): Cannot assign requested address
   at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, String callerName)
   at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
   at System.Net.Sockets.Socket.Bind(EndPoint localEP)
   at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransportOptions.CreateDefaultBoundListenSocket(EndPoint endpoint)
   at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketConnectionListener.Bind()
   at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransportFactory.BindAsync(EndPoint endpoint, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.TransportManager.BindAsync(EndPoint endPoint, ConnectionDelegate connectionDelegate, EndpointConfig endpointConfig, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.<>c__DisplayClass30_0`1.<<StartAsync>g__OnBind|0>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindEndpointAsync(ListenOptions endpoint, AddressBindContext context, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Server.Kestrel.Core.ListenOptions.BindAsync(AddressBindContext context, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.EndpointsStrategy.BindAsync(AddressBindContext context, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindAsync(IEnumerable`1 listenOptions, AddressBindContext context, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.BindAsync(CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Hosting.WebHost.StartAsync(CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Hosting.WebHostExtensions.RunAsync(IWebHost host, CancellationToken token, String startupMessage)
   at Microsoft.AspNetCore.Hosting.WebHostExtensions.RunAsync(IWebHost host, CancellationToken token, String startupMessage)
   at Microsoft.AspNetCore.Hosting.WebHostExtensions.RunAsync(IWebHost host, CancellationToken token)
   --- End of inner exception stack trace ---
   --- End of inner exception stack trace ---
   at WireMock.Server.WireMockServer..ctor(WireMockServerSettings settings)
   at WireMock.Server.WireMockServer.Start(WireMockServerSettings settings)
@domwvitality commented on GitHub (May 16, 2024): Hi @StefH , Apologies for the delay. I've just got round to testing that build and it fails for me when starting the server. I'm using the same snippet... ```c# Service = WireMockServer.Start(new WireMockServerSettings { Urls = new[] { "http://172.18.0.1:8102" } }); ``` but when I execute I get this error... ```c# WireMock.Exceptions.WireMockException: Service start failed with error: One or more errors occurred. (Cannot assign requested address) ---> System.AggregateException: One or more errors occurred. (Cannot assign requested address) ---> System.Net.Sockets.SocketException (99): Cannot assign requested address at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, String callerName) at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.Sockets.Socket.Bind(EndPoint localEP) at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransportOptions.CreateDefaultBoundListenSocket(EndPoint endpoint) at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketConnectionListener.Bind() at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransportFactory.BindAsync(EndPoint endpoint, CancellationToken cancellationToken) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.TransportManager.BindAsync(EndPoint endPoint, ConnectionDelegate connectionDelegate, EndpointConfig endpointConfig, CancellationToken cancellationToken) at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.<>c__DisplayClass30_0`1.<<StartAsync>g__OnBind|0>d.MoveNext() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindEndpointAsync(ListenOptions endpoint, AddressBindContext context, CancellationToken cancellationToken) at Microsoft.AspNetCore.Server.Kestrel.Core.ListenOptions.BindAsync(AddressBindContext context, CancellationToken cancellationToken) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.EndpointsStrategy.BindAsync(AddressBindContext context, CancellationToken cancellationToken) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindAsync(IEnumerable`1 listenOptions, AddressBindContext context, CancellationToken cancellationToken) at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.BindAsync(CancellationToken cancellationToken) at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken) at Microsoft.AspNetCore.Hosting.WebHost.StartAsync(CancellationToken cancellationToken) at Microsoft.AspNetCore.Hosting.WebHostExtensions.RunAsync(IWebHost host, CancellationToken token, String startupMessage) at Microsoft.AspNetCore.Hosting.WebHostExtensions.RunAsync(IWebHost host, CancellationToken token, String startupMessage) at Microsoft.AspNetCore.Hosting.WebHostExtensions.RunAsync(IWebHost host, CancellationToken token) --- End of inner exception stack trace --- --- End of inner exception stack trace --- at WireMock.Server.WireMockServer..ctor(WireMockServerSettings settings) at WireMock.Server.WireMockServer.Start(WireMockServerSettings settings) ```
Author
Owner

@StefH commented on GitHub (May 17, 2024):

On my system:

ipconfig

Ethernet adapter vEthernet (Default Switch):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::44c8:b60d:87e1:8437%27
   IPv4 Address. . . . . . . . . . . : 172.19.80.1
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . :

WireMock.Net

var serverOnPrivateIPAddress172_19 = WireMockServer.Start(new WireMockServerSettings
{
    Urls = new[] { "https://172.19.80.1:8103" }
});
System.Console.WriteLine($"{string.Join(", ", serverOnPrivateIPAddress172_19.Urls)}");
serverOnPrivateIPAddress172_19.Stop();

This works fine.

Are you sure you that 172.18.0.1 is your local ip-address from your PC?

@StefH commented on GitHub (May 17, 2024): On my system: ### ipconfig ``` Ethernet adapter vEthernet (Default Switch): Connection-specific DNS Suffix . : Link-local IPv6 Address . . . . . : fe80::44c8:b60d:87e1:8437%27 IPv4 Address. . . . . . . . . . . : 172.19.80.1 Subnet Mask . . . . . . . . . . . : 255.255.240.0 Default Gateway . . . . . . . . . : ``` ### WireMock.Net ``` c# var serverOnPrivateIPAddress172_19 = WireMockServer.Start(new WireMockServerSettings { Urls = new[] { "https://172.19.80.1:8103" } }); System.Console.WriteLine($"{string.Join(", ", serverOnPrivateIPAddress172_19.Urls)}"); serverOnPrivateIPAddress172_19.Stop(); ``` This works fine. Are you sure you that 172.18.0.1 is your local ip-address from your PC?
Author
Owner

@domwvitality commented on GitHub (May 17, 2024):

Hi @StefH ,

My apologies, you're right, the IP was wrong.
Retested with http://172.19.0.1 and all is working as expected.

@domwvitality commented on GitHub (May 17, 2024): Hi @StefH , My apologies, you're right, the IP was wrong. Retested with http://172.19.0.1 and all is working as expected.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#597