views:

422

answers:

1

There's so much stuff on this online but no one seems to be able to answer this... Hopefully someone here will be!

So i have a WCF web service hosted at godaddy.com. Everything works great when i try accessing it using:

http://www.domain.com/DataService.svc

problem is when i remove the www i.e.

http://domain.com/DataService.svc

Here's my web.config servicemodel section:

<system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior name="DataServiceBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<services>
  <service behaviorConfiguration="DataServiceBehavior"
      name="DataService">

    <endpoint address="" binding="basicHttpBinding" contract="IDataService"/>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
</services>

Here's my ServiceReferences.ClientConfig

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_IDataService" maxBufferSize="2147483647"
                maxReceivedMessageSize="2147483647">
                <security mode="None" />
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://www.domain.ca/DataService.svc" binding="basicHttpBinding"
            bindingConfiguration="BasicHttpBinding_IDataService" contract="Web.IDataService"
            name="BasicHttpBinding_IDataService" />
    </client>
</system.serviceModel>

My service is using a CustomServiceFactory

public class CustomServiceHostFactory : ServiceHostFactory
{
    /// <summary>
    /// A custom method to eliminate multiple base addresses from the IIS host creation process
    /// </summary>
    /// <param name="serviceType">The service type to be created</param>
    /// <param name="baseAddresses">A list of the base addresses</param>
    /// <returns>A service host</returns>
    protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
    {
        if (baseAddresses.Length > 1)
        {
            ServiceHost customServiceHost =
                new ServiceHost(serviceType, baseAddresses[1]);
            return customServiceHost;
        }

        return new ServiceHost(serviceType, baseAddresses[0]);
    }
}

Basically what i would like is my WCF webservice to be reachable whether the user enters domain.com or www.domain.com into his (or her) browser.

Any help will be greatly appreciated!

ps. Running IIS 7 with ASP 3.5

Thnaks! Simon

+1  A: 

You're running across a cross domain issue. See here for a list of reasons as to why it happens. As it turns out "www" and no-www are different domains even though they don't seem like it. You'll need to add a cross domain file. See Tim's blog for good info

Erik Mork
It's weird bc i had a clientaccesspolicy.xml but its only when i added the crossdomain.xml thats it finally worked. Could it be due to godaddy? Well at least its working now. Thanks!
Simon Levy
Interesting. It's actually easy to muck up cross domain files. Maybe this tool will help: http://www.franksworld.com/Utilities/CrossDomainPolicyChecker/Default.aspx gl!
Erik Mork