Windows Server 2012 R2上Windows Service Platform上的WCFNotSupportedException

时间:2018-11-28 17:53:49

标签: c# wcf windows-services windows-server

我正在Windows服务中托管WCF服务。它可以在Windows,Windows 7,Windows 8,Windows 10,Windows Server 2016等多个版本中使用。

但是,在 Windows Server 2012 R2 中,它不起作用。

当我尝试启动服务时,出现此错误:

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...

这是服务代码:

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;
            }
        }
    }
}

ConfigurationManager.AppSettings [“ EndPointHttp”] 中的地址为 http://localhost:46125/bioacesso/terminais.svc

防火墙已禁用, 没有使用端口46125的应用程序(我已通过netstat命令验证) 我正在使用管理员帐户。

我在这里看到了一些这样的帖子:WCF : PlatformNotSupportedException when running Server Projects

但是,任何建议的解决方案都适合我的情况,

有人知道会发生什么吗?

1 个答案:

答案 0 :(得分:1)

我在此链接中找到了答案

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

http驱动程序已被禁用,在Windows 2012中,您只能在注册表中进行更改。

HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ HTTP

开始必须为3(已禁用4)