gpt4 book ai didi

c# - WCF : PlatformNotSupportedException when running Server Projects

转载 作者:行者123 更新时间:2023-11-30 12:50:58 29 4
gpt4 key购买 nike

我提前为过于含糊致歉,如果您需要任何精确度,我会尽力提供。

我编译了 2 个不同的 WCF“代码项目”示例应用程序,无论我启动哪个应用程序,我都会收到以下异常,所以我猜我的机器上配置有误:

编辑
我在另一台机器上试过(相同的操作系统,win 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并删除上述相同的异常
如前所述,这可能是一个 UAC 问题 here但这并没有解决我的问题。
操作系统是 Windows 7 x64

提前致谢。

最佳答案

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

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

关于c# - WCF : PlatformNotSupportedException when running Server Projects,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7967674/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com