SIGN UP MEMBER LOGIN:    
ARTICLE

Multiple base addresses for WCF Service

Posted by Dhananjay Kumar Articles | SharePoint November 29, 2010
In this article we will see how to explicitly set address for each EndPoint in our service.
Reader Level:

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 

1.gif 

And we use it in service configuration as below, 

2.gif 

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. 

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

Now at endpoint configuration, we will configure it as below 

4.gif
 
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>

Login to add your contents and source code to this article
share this article :
post comment
 

Hi Dhananjay, In my project I am trying to host WCF service(WCF library) in WAS so I am referring that assembly and registering in hosting web .svc file. My base address for service and Host is same net.tcp://localhost:8884/CPService. My working plot form is VS 2010 ,OS win 7. I enabled all binding and protocols by executing appcme.exe but I am getting error as net.Tcp is not enabled. Can you help me. Thanks in advance, Manjunath

Posted by Manjunath BE Mar 17, 2011
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor