WCF:运行服务器项目时的PlatformNotSupportedException

我提前道歉,因为太过模糊,如果你需要任何精确度,我会尽力给予它。

我编译了2个不同的WCF“代码项目”示例应用程序,无论我发布的是什么,我都会遇到以下exception,所以我猜我的机器上有一些配置错误:

编辑
我尝试了另一台机器(相同的操作系统,赢得7 64),它工作正常。
我只是无法弄清楚我的电脑上有什么配置错误或丢失。

{"Operation is not supported on this platform."} 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.HttpChannelListener.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 WCFService.MainForm.startWCFServer() in D:\xxx\MainForm.cs:line 77 

以下是代码。 我猜没有什么不寻常的基本WCF东西。

  private ServiceHost host = null; public void startWCFServer() { // Create the url that is needed to specify where the service should be tarted urlService = "net.tcp://" + "127.0.0.1" + ":8000/MyService"; // Instruct the ServiceHost that the type that is used is a ServiceLibrary.service1 host = new ServiceHost(typeof(ServiceLibrary.service1)); host.Opening += new EventHandler(host_Opening); host.Opened += new EventHandler(host_Opened); host.Closing += new EventHandler(host_Closing); host.Closed += new EventHandler(host_Closed); // The binding is where we can choose what transport layer we want to use. HTTP, TCP ect. NetTcpBinding tcpBinding = new NetTcpBinding(); tcpBinding.TransactionFlow = false; tcpBinding.Security.Transport.ProtectionLevel = System.Net.Security.ProtectionLevel.EncryptAndSign; tcpBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows; tcpBinding.Security.Mode = SecurityMode.None; // <- Very crucial // Add endpoint host.AddServiceEndpoint(typeof(ServiceLibrary.IService1), tcpBinding, urlService); // A channel to describe the service. Used with the proxy scvutil.exe tool ServiceMetadataBehavior metadataBehavior; metadataBehavior = host.Description.Behaviors.Find(); if (metadataBehavior == null) { // This is how I create the proxy object that is generated via the svcutil.exe tool metadataBehavior = new ServiceMetadataBehavior(); //metadataBehavior.HttpGetUrl = new Uri("http://" + _ipAddress.ToString() + ":8001/MyService"); metadataBehavior.HttpGetUrl = new Uri("http://" + "127.0.0.1" + ":8001/MyService"); metadataBehavior.HttpGetEnabled = true; metadataBehavior.ToString(); host.Description.Behaviors.Add(metadataBehavior); urlMeta = metadataBehavior.HttpGetUrl.ToString(); } host.Open(); // <---- EXCEPTION BLOWS HERE } 

细节 :
演示应用程序在这里和这里,并删除上述相同的exception
它可能是这里所述的UAC问题但是这并没有解决我的问题。
操作系统是Windows 7 x64

提前致谢。

这是您无权在给定地址创建服务主机时获得的消息。 在您的情况下,您将使用NetTcpBinding获取此信息。 以下是一些可能的解决方案 – 您只需要完成它们。

  1. 另一个进程是使用相同的绑定 – TCP端口8000(IIS?)
  2. 您没有以管理员身份运行VS.NET
  3. 未安装Windows进程激活服务(WAS)(net.tcp绑定需要Windowsfunction)
  4. 未安装Windows Communication Foundation HTTP /非HTPP激活(.NET Framework 3.x下的Windowsfunction)
  5. 防火墙阻止了Net.Tcp的成功通信。

我不确切知道究竟发生了什么以及为什么这样做,但是评论以下行并且没有将metadataBehavior添加到host.Description.Behaviors修复了prob:

  host.Description.Behaviors.Add(metadataBehavior); 

我真的不需要这个function,所以可以挤压它,但我仍然想知道为什么这会导致exception…(特别是那是在我的合作伙伴的工作站上工作,所以我相信它与“一些设置某处“

在其他项目上评论完全相同的线条也会使它们也起作用,所以毫无疑问会留下。

根据这个: http : //social.msdn.microsoft.com/forums/en-US/wcf/thread/b67d03d9-e2e6-40e6-aa44-2af6ce5a8a38/问题是元数据绑定不是http所以防火墙阻止它。

1->打开SQL Server

2->右键单击数据库并选择属性

3->单击选项(左侧面板)更改为数据库集合,选择Latin1_General_CI_AI

任务合并。