1
votes

I am unable to get WCF services to run on a shared server using IIS.

I have tried several tutorials: http://technologyriver.blogspot.com/2012/02/prerequisites-check-windows-7.html http://msdn.microsoft.com/en-us/library/ms733766.aspx

I've read blogs about executing command line instructions to enable WCF support on IIS. However, the hosting company refuses to run the command on their box.

The services work fine on my dev machine. However, I just cannot get the services to run on the remote server.

When clicking on an svc file I get the following error:

HTTP Error 404.3 - Not Found

The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.*

svc file:

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

Web.config:

<service name="MyService" behaviorConfiguration="MyServiceBehavior">
    <endpoint contract="IMyService" binding="basicHttpBinding">
      <identity>
        <dns value="http://www.mydomain.com" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />

    <host>
      <baseAddresses>
        <add baseAddress="http://www.mydomain.com:8732/Services/Service/" />
      </baseAddresses>
    </host>
  </service>

Service.cs:

using System;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;

// A WCF service consists of a contract (defined below as IMyService, DataContract1), 
// a class which implements that interface (see MyService), 
// and configuration entries that specify behaviors associated with 
// that implementation (see <system.serviceModel> in web.config)

[ServiceContract()]
public interface IMyService
{
    [OperationContract]
    string MyOperation1(string myValue1);
    [OperationContract]
    string MyOperation2(DataContract1 dataContractValue);
}

public class MyService : IMyService
{
    public string MyOperation1(string myValue1)
    {
        return "Hello: " + myValue1;
    }
    public string MyOperation2(DataContract1 dataContractValue)
    {
        return "Hello: " + dataContractValue.FirstName;
    }
}

[DataContract]
public class DataContract1
{
    string firstName;
    string lastName;

    [DataMember]
    public string FirstName
    {
        get { return firstName; }
        set { firstName = value; }
    }
    [DataMember]
    public string LastName
    {
        get { return lastName; }
        set { lastName = value; }
    }
}

public class MyServiceHostFactory : ServiceHostFactoryBase
{
    protected virtual ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
    {
        // Specify the exact URL of your web service
        Uri webServiceAddress = new Uri("http://www.mydomain.com/MyService.svc");

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

    public override ServiceHostBase CreateServiceHost(string constructorString, Uri[] baseAddresses)
    {
        throw new NotImplementedException();
    }
}

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

    protected override void ApplyConfiguration()
    {
        base.ApplyConfiguration();
    }
}
2
Is the url you are trying to access in this format? "mydomain.com:8732/Services/Service/MyService.svc"?Nexus23
I'm simply clicking on the svc file in the website directory.Scott Nimrod
I've even started over and took the WCF default project app and published it. It runs the simple default service as-is on my local box. However, I get the same error message when publishing it to a remote server.Scott Nimrod

2 Answers

1
votes

I had to switch hosts.

I was originally using DiscountASP.Net and they refused my request to ensure WCF settings were enabled and told me that I needed to hire a developer or follow the MS IIS specs. (P.S. They didn't know that I'm actually an SDET.)

As a result, I had to switch to another provider (i.e. Winhost). Things just work now without me having to do any crazy webconfig alterations or ServiceHostFactory coding crap that the previous host wanted me to do that had no success.

I spent 5 days reopening tickets with their tech support until I finally switched to a hosting company that actually supports WCF Services.

Thanks Winhost for ending this dreadful nightmare!

0
votes

It seemed to be access/configurability problem on remote server then.

Try checking following areas for the deployed service.

  • Binding of the WCF service is configured correctly, DNS and port (default is 80)
  • Authentication Mode of service (Anonymous access should be allowed to browser through WSDL)
  • Permissions granted to the website (directory and user permissions)

If none of them work, then can you list down the steps you followed when service is deployed?