Today, we are going to discuss a common issue that you may find when running WCF RIA service on a shared hosting server. ASPHostCentral.com, as the premier ASP.NET and Windows Hosting provider, proudly presents this article to anyone and we believe it will help many ASP.NET communities; especially to those who are using WCF RIA Service. In case you are looking for WCF RIA Service Hosting, you can always consider ASPHostCentral.com and you can start from our lowest Standard Plan @$4.99/month to host your WCF-service site.

One of the most common errors that you may find when running your WCF RIA Service on a shared hosting server is the error message:

This collection already contains an address with scheme http.  There can be at most one address per scheme in this collection.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: This collection already contains an address with scheme http.  There can be at most one address per scheme in this collection.”

This error message can be retrieved on the Event Viewer window on the server. If you do not have an access to the server, you may contact your hosting provider to trace this error for you.


Solution:

This problem is caused by the fact that WCF only supports 1 IIS host header. Your hosting provider may have more than 2 host headers, namely www.yourDomain.com and yourDomain.com. Therefore, you may need to remove one of the host headers from the IIS.


Other Alternative Solution:

The other alternative solution you can consider is to create a separate .SVC file. The solution, since WCF services hosted in IIS can have only one Base Address was to create a custom service factory to intercept and remove the additional unwanted base addresses that IIS was providing. Your default IIS settings will have 2 entries of host headers, namely: www.yourDomain.com and yourDomain.com. You then need to customize your .svc file to specify a custom service factory. You are then able to create your custom factory by inheriting from ServiceHostFactory and overriding as required.The following is the code:

class CustomHostFactory : ServiceHostFactory
    {
        protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
        {
              CustomHost customServiceHost =
                new CustomHost(serviceType, baseAddresses[1]);
            return customServiceHost;
        }
    }   

class CustomHost : ServiceHost

    {
        public CustomHost(Type serviceType, params Uri[] baseAddresses)
            : base(serviceType, baseAddresses)
        { }
        protected override void ApplyConfiguration()
        {
            base.ApplyConfiguration();
        }
    }

You need to pass through baseAddresses[1] (which was the www. address) but it would probably be wise to specify that address you want to prevent changes by your web host from impacting your code.Please refer to this article at http://blogs.msdn.com/rampo/archive/2008/02/11/how-can-wcf-support-multiple-iis-binding-specified-per-site.aspx for further information.


Reasons to trust your WCF-based website to ASPHostCentral.com

What we think makes ASPHostCentral.com so compelling is how deeply integrated all the pieces are. We integrate and centralize everything--from the systems to the control panel software to the process of buying a domain name. For us, that means we can innovate literally everywhere. We've put the guys who develop the software and the admins who watch over the server right next to the 24-hour Fanatical Support team, so we all learn from each other:

- 24/7-based Support - We never fall asleep and we run a service that is operating 24/7 a year. Even everyone is on holiday during Easter or Christmas/New Year, we are always behind our desk serving our customers
- Excellent Uptime Rate - Our key strength in delivering the service to you is to maintain our server uptime rate. We never ever happy to see your site goes down and we truly understand that it will hurt your onlines business. If your service is down, it will certainly become our pain and we will certainly look for the right pill to kill the pain ASAP
- High Performance and Reliable Server - We never ever overload our server with tons of clients. We always load balance our server to make sure we can deliver an excellent service, coupling with the high performance and reliable server
- Experts in WCF RIA Service Hosting - Given the scale of our environment, we have recruited and developed some of the best talent in the hosting technology that you are using. Our team is strong because of the experience and talents of the individuals who make up ASPHostCentral
- Daily Backup Service - We realise that your website is very important to your business and hence, we never ever forget to create a daily backup. Your database and website are backup every night into a permanent remote tape drive to ensure that they are always safe and secure. The backup is always ready and available anytime you need it
- Easy Site Administration - With our powerful control panel, you can always administer most of your site features easily without even needing to contact for our Support Team. Additionally, you can also install
more than 100 FREE applications directly via our Control Panel in 1 minute!

Happy hosting!