0

I have wcf service which running with http and net.tcp protocol on IIS. Now I want to get live IP address with port that is assigned to them respectively. Furthermore,I want it in wcf service project. Please give your suggestion.

Amit Bhatt
  • 45
  • 10

1 Answers1

0

When you set up your WCF service using a web.config file, you specify the port as shown in the web.config below in the baseAddresses element:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="ServiceClassName">
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:12345/ServiceClassName"/>
          </baseAddresses>
        </host>
        <endpoint address=""
                  binding="netTcpBinding"
                  contract="ServiceInterfaceName" />
      </service>
    </services>
  </system.serviceModel>
</configuration>

The IP address is a bit more tricky. Is there a reason that the IP address is not known at runtime or is there a specific reason that you cannot use the host name to connect to your service?

João Lourenço
  • 736
  • 5
  • 8
  • definately.this is one approach but in this approach I required to change base address whenever my service port or ip changed. but what I mean is that is there any approach where I can get live IP addresses of all assigned protocol like http,net.tcp in wcf project which running using some class like (Dns.GetHostAddresses) – Amit Bhatt Sep 06 '16 at 05:24
  • That is correct. Remember that there is a separation between development and deployment. The configuration of hostnames etc is done in the deployment step. How often is the port for your WCF service changing anyway? – João Lourenço Sep 06 '16 at 05:29
  • you are surely right. but I am looking for a way where nothing is hard code so. I admire your suggestion. thanks – Amit Bhatt Sep 06 '16 at 05:43
  • So create the configuration via code and not via .conf. – ilansch Sep 06 '16 at 06:02