Last post Jul 25, 2013 06:15 AM by Steven Cheng - MSFT
Jul 24, 2013 11:59 AM|ramakrishna431|LINK
I have a setup application in which a WCF service is self hosted in Windows service. So i have given the base address as
<add baseAddress="http://localhost:Port/SomeService.svc" />
in both WCF config file and Windows Service config file
Now i need to check whether PortNumber is available in client machine and if it is not available i need to change in both config files.
How can i acheive this programatically, changing config file at runtime
Jul 25, 2013 06:15 AM|Steven Cheng - MSFT|LINK
As for WCF service (host or client), it naturally support programmtic configuration and setup, so you can completely change to startup and configure your service via code instead of using config file (for your windows service hoste WCF service).
#How to: Programmatically Configure a WCF Endpoint
#WCF Essentials—Programmatic Endpoint Configuration
#WCF Essentials—Programmatic Client Configuration
and for detecting used tcp port, here are some former threads which have mentioned some approach to do it in .NET/C#:
#C# How to: Check if a Tcp Port is in use
#In C#, how to check if a TCP port is available?