2011-11-01 107 views
4

我很抱歉太过于模糊,如果您需要任何精度,我会尽我所能给它。WCF:PlatformNotSupportedException当运行服务器项目

我整理了2个不同的WCF“代码项目”示例应用程序,并且我得到以下异常无论一个我启动,所以我想,这正是我的机器上一些错误配置:

编辑
我尝试在不同的机器上(相同的操作系统,赢得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<ServiceMetadataBehavior>(); 
      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 

    } 


详情:
演示应用程序是herehere和删除上述
描述为表示here但是这并没有解决我的问题,这可能是一个UAC的问题相同的异常。
操作系统是Windows 7 x64

在此先感谢。

+0

您是否拥有Windows Communication Foundation HTTP/Non-HTTP Activation窗口功能?这些选项位于控制面板 - >程序和功能 - >打开或关闭Windows功能 - > Microsoft .NET Framework 3.x(刚刚意识到您的示例是.NET 3.5而不是.NET 4) – SliverNinja

回答

0

我不知道到底发生了什么,为什么恰恰, 但注释以下行,并且不添加metadataBehavior到 host.Description.Behaviors修复概率:

host.Description.Behaviors.Add(metadataBehavior); 

我不真的不需要这个功能,所以它可以挤压它,但我仍然想知道为什么这会导致例外......(特别是那是在我的合作伙伴的工作站上工作,所以我确信它必须与“某些设置某处“

在其他项目上评论完全相同类型的行使它们也可以工作,所以毫无疑问就剩下了。

2

这是当您无权在给定地址创建服务主机时获得的消息。在你的情况下,你正在使用NetTcpBinding。这里有一些可能的解决方案 - 你只需要贯穿它们。

  1. 另一个进程正在使用相同的结合 - TCP端口8000(IIS?)
  2. 您没有运行VS.NET作为管理员
  3. Windows进程激活服务(WAS)未安装(Windows功能需要net.tcp绑定)
  4. 未安装Windows Communication Foundation HTTP/Non-HTPP激活(在.NET Framework 3.x下的窗口功能)
  5. 防火墙阻止成功的Net.Tcp通信。
+0

谢谢。 1 \我使用TCPView/netstat来监视端口使用情况,并且端口8000是免费的。当一个端口已经被监听时,我得到另一个异常(更明确)。 2 \我正在运行VS作为管理员+我在VS外部发布了exe文件,结果如同admin,结果相同 –

+0

@SilverNinja:将127.0.0.1更改为我的真实IP导致出现以下错误“请求的地址在其上下文中无效”以及yes metadataBehavior为空 –

+0

您有网络激活服务吗?请参阅http://stackoverflow.com/questions/3561286/wcf-tcp-binding-the-requested-address-is-not-valid-in-its-context-error – SliverNinja

0

1->打开SQL Server

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

3->点击选项(左图)数据库收集的变化选择complated Latin1_General_CI_AI

使命。