Archive for May, 2009

The Problem :I faced this issue when hosting my WCF application on my shared hosting, that’s what I got:

” This collection already contains an address with scheme http.  There can be at most one address per scheme in this collection.
Parameter name: item “

The solution involves two simple steps
1. Creating a Host Factory class in WCF project

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ServiceModel.Activation;
using System.ServiceModel;

namespace <Your namespace>
{
/// <summary>
/// Summary description for CoreServiceHostFactory
/// </summary>
public class CoreServiceHostFactory : ServiceHostFactory
{
protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
{
// Specify the exact URL of your web service
Uri webServiceAddress = new Uri(“http://yourdomain/yourservice.svc”);

ServiceHost webServiceHost = new ServiceHost(serviceType, webServiceAddress);
return webServiceHost;
}
}
}

2. Adding factory reference in .svc file

<%@ ServiceHost Language=”C#” Debug=”true” Service=”YourNameSpace.YourService”
CodeBehind=”~/App_Code/YourService.cs” Factory=”YourNameSpace.CoreServiceHostFactory” %>


Using the approach above I was able to host my WCF right.

The other easy solution I found:

Add a serviceHostingEnvironment section in <system.serviceModel> somewhat like

<serviceHostingEnvironment aspNetCompatibilityEnabled=”true”>
<baseAddressPrefixFilters>
<add prefix=”http://yourdomain.com/servicename.svc”/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>

working 100% now

Handling SQL server 2005 data types in dotnet

Hi

Many of us use SQL server as our preferred choice with our .NET applications. While designing the database we have number of options in terms of selecting data types for our columns. We should be clear about the usage and scope and  mapping of data from Db to our App.

Here is a list of some good articles that may help you decide the most appropriate data type for your column and then convert it into an equivalent .NET data type.

Choosing data type :http://dotnetguts.blogspot.com/2007/10/datatypes-in-sql-server-2005.html

SQL data  types and categories: http://msdn.microsoft.com/en-us/library/ms187752.aspx

Mapping table: http://msdn.microsoft.com/en-us/library/ms131092.aspx