【发布时间】:2019-04-30 17:03:20
【问题描述】:
我在 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,
但是,建议的任何解决方案都适用于我的情况,
有人知道会发生什么吗?
【问题讨论】:
标签: c# wcf windows-services windows-server