If we do not want to explicitly set address for each EndPoint in our service then we define BASE ADDRESS for the EndPoint exposed for our service
And we use it in service configuration as below,
The advantage of having base address is that, if we are changing the service URL, we need to change at only one place instead of going and changing address of each endpoint.
WCF allow us to give multiple base addresses for each type of protocol. And at the run time corresponding endpoint will take the base address.
In above configuration, we added one more base address using net.tcp protocol.
Now at endpoint configuration, we will configure it as below
At the run time WCF automatically will map base address to corresponding endpoint with matched protocol.
For reference full Web.Config will look like
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="MyBeh">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="WcfService1.Service1" behaviorConfiguration="MyBeh">
<endpoint address=""
binding="basicHttpBinding"
contract="WcfService1.IService1"/>
<endpoint address="nete"
binding ="netTcpBinding"
contract ="WcfService1.IService1"/>
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
<endpoint address="mex1"
binding="mexTcpBinding"
contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8181/Service1.svc/"/>
<add baseAddress="net.tcp://localhost:9876/Service1.svc/"/>
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>