views:

382

answers:

3

I created a very simple WCF and deployed it to the hosting provider by doing a "Copy Website". Locally, it's setup to use the development server (not in IIS). The domain is under Full trust permissions. Locally, I can get to the Service.svc page, but not in the hosting provider.

The code is as follows:

Service.svc

<%@ ServiceHost Language="C#" Debug="true" Service="Service" CodeBehind="~/App_Code/Service.cs" Factory="CustomHostFactory" %>

Service.cs

// NOTE: If you change the class name "Service" here, you must also update the reference to "Service" in Web.config and in the associated .svc file.
public class Service : IService
{
    public string GetData(int value)
    {
        return string.Format("You entered: {0}", value);
    }

    public CompositeType GetDataUsingDataContract(CompositeType composite)
    {
        if (composite.BoolValue)
        {
            composite.StringValue += "Suffix";
        }
        return composite;
    }
}


class CustomHostFactory : ServiceHostFactory
{
    protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
    {
        // If more than one base address exists then return the second address,
        // otherwise return the first address
        if (baseAddresses.Length > 1)
        {
            return new ServiceHost(serviceType, baseAddresses[1]);
        }
        else
        {
            return new ServiceHost(serviceType, baseAddresses[0]);
        }
    }
}

class CustomHost : ServiceHost
{
    public CustomHost(Type serviceType, params Uri[] baseAddresses)
        : base(serviceType, baseAddresses)
    { }
}

Web.config

  <system.serviceModel>
    <services>
      <service name="Service" behaviorConfiguration="ServiceBehavior">
        <!-- Service Endpoints -->
        <endpoint address="" binding="wsHttpBinding" contract="IService">
          <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          -->
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

Any help?

+1  A: 

A few things:

  • did you create a virtual directory at your hosting provider? The *.svc file must be deployed into the root of a virtual directory

  • did you navigate to http://yourserver/virtualdirectory/yourservice.svc ? When hosting in IIS, all the base address stuff is moot and will be ignored - the service address is defined by the web server name, virtual directory, and name of the *.svc file

marc_s
I created a virtual directory (name: WCFService) and target type is a folder pointing to wwwroot. I have all my files under wwwroot, so the folder structure looks like this:wwwroot -> App_Code, App_Data, Service.svc, Web.config. I then browsed to http://aa.xx.com/WCFService/Service.svc and I get the same error
I also tried it after moving all the files to wwwroot\WCFService folder but have the same issue :(
Did you get this working? I'm having the same issue and really tying to get this working.
ElHaix
A: 

Any help is really appreciated. Thanks

A: 

I just ended up with the same issue. Are you using the CustomHostFactory from Rob Zelt's article: WCF: This collection already contains an address with scheme http?

The baseAddresses getting passed in will contain all the bindings set up for IIS; host headers, ports, http/https. The binding you pass to ServiceHost needs to match the URL that the WCF request to coming to - otherwise you'll get "resource cannot be found".

russau