Search code examples
c#wcfwindows-serviceswindows-server

WCF on Windows Service PlatformNotSupportedException On Windows Server 2012 R2


I'm hosting a WCF service in an Windows Service. It works in several versions of Windows, Windows 7, Windows 8, Windows 10, Windows Server 2016...

However, in Windows Server 2012 R2 it doesn't work.

When I try to start the service I get this error:

Service can not be started. System.PlatformNotSupportedException: This platform does not support operation.
   at System.Net.HttpListener..ctor()
   at System.ServiceModel.Channels.SharedHttpTransportManager.OnOpen()
   at System.ServiceModel.Channels.TransportManager.Open(TransportChannelListener channelListener)
   at System.ServiceModel.Channels.TransportManagerContainer.Open(SelectTransportManagersCallback selectTransportManagerCallback)
   at System.ServiceModel.Channels.TransportChannelListener.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.HttpChannelListener`1.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Channe...

Here is the service code:

using System;
using System.Configuration;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.ServiceProcess;

namespace WindowsService
{
    public partial class GerenciadorMorphoService : ServiceBase
    {
        private ServiceHost mHost = null;

        public GerenciadorMorphoService()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            if (mHost != null)
            {
                mHost.Close();
            }

            Uri EndPoint = new Uri(ConfigurationManager.AppSettings["EndPointHttp"]);
            mHost = new ServiceHost(typeof(Terminais.Terminal), EndPoint);

            ServiceMetadataBehavior behave = new ServiceMetadataBehavior
            {
                HttpGetEnabled = true
            };

            mHost.Description.Behaviors.Add(behave);

            mHost.Open();
        }

        protected override void OnStop()
        {
            if (mHost != null)
            {
                mHost.Close();
                mHost = null;
            }
        }
    }
}

The address in ConfigurationManager.AppSettings["EndPointHttp"] is http://localhost:46125/bioacesso/terminais.svc

The firewall is disabled, There is no application using the port 46125 (I verified with the netstat command) I am using the Administrator account.

I saw some posts here like this: WCF : PlatformNotSupportedException when running Server Projects,

however, any solution suggested worked for my case,

Anybody knows what can be happening?


Solution

  • I found the answer in this link

    http://www.toughdev.com/content/2017/12/fixing-platformnotsupportedexception-when-running-a-window-communication-foundation-application/

    The http driver was disabled, and in the windows 2012 you can only change that in the registry.

    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\HTTP

    The key Start has to be 3 (4 is disabled)