Multiple base addresses for WCF Service

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

clip_image002

And we use it in service configuration as below,

clip_image004

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.

clip_image006

In above configuration, we added one more base address using net.tcp protocol.

Now at endpoint configuration, we will configure it as below

clip_image008

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="<a href="http://localhost:8181/Service1.svc/&quot;/">http://localhost:8181/Service1.svc/"/</a>>
 <add baseAddress="net.tcp://localhost:9876/Service1.svc/"/>
 </baseAddresses>
 </host>
 </service>
 </services>
 </system.serviceModel>

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a website or blog at WordPress.com