My purpose is:
run a self-hosting WCF service, whose base address is set at runtime according to the available network card/s; clients discover the service and get the address.
Previous answers:
I have found the same purpose and a suggested solution here
My problem:
When I run the hosting console app an exception is thrown here:
var host = new ServiceHost(typeof(WcfPingTest), new Uri("http://*:7400/WcfPing"));
Exception details: System.UriFormatException: Invalid URI: The hostname could not be parsed
If I replace * with localhost, it works, but it does not satisfy my task, that is: get the real ip address from the client, and not the hard-coded one.
I have tried also to do it inside the app.config file, but the exception is the same:
Where did I go wrong?
Additional info: C# code, .NET Framework 4.5
UPDATE: Wildcard usage works using in app.config file:
<baseAddresses><add baseAddress="http://*:7400/WcfPing" /></baseAddresses>
and in console app:
var host = new ServiceHost(typeof(WcfPingTest))
On the other hand, Uri
constructor does not accept a uriString parameter with the * char inside
NEXT TOPIC: with the above source code, my clients get the uri at runtime, but this uri contains the MY_COMPUTER_NAME like http://MY_COMPUTER_NAME:7400/WcfPing
, intead of
http://MY_IP_ADDRESS:7400/WcfPing
Is there any method to get the actual IP address? (I have multiple NICs for different local networks)