WCF:运行服务器项目时出现 PlatformNotSupportedException [英] WCF : PlatformNotSupportedException when running Server Projects

查看:33
本文介绍了WCF:运行服务器项目时出现 PlatformNotSupportedException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我预先为过于含糊而道歉,如果您需要任何精确性,我会尽力提供.

I apologize in advance for being too vague, if you need any precision I will do my best to give it.

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

I compiled 2 different WCF "Code Project" sample apps, and I am getting the following exception whatever the one I launch, so I guess there is something misconfigured on my machine :

编辑
我在另一台机器上尝试过(相同的操作系统,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 东西.

Below is the code. Nothing unusual, basic WCF stuff I guess.

    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

    }


详细信息:
演示应用程序位于此处此处 并删除上述相同的异常
这可能是 UAC 问题 此处 但这并没有解决我的问题.
操作系统是 Windows 7 x64

DETAILS :
Demo Apps are here and here and dropping the same exception described above
It could be an UAC issue as stated here But that did not fix my issue.
OS is Windows 7 x64

提前致谢.

推荐答案

我不知道到底发生了什么以及为什么会发生,但注释以下行,而不是将 metadataBehavior 添加到host.Description.Behaviors 修复了问题:

I don't know exactly what happens and why precisely, but commenting the following line and not adding metadataBehavior to host.Description.Behaviors fixes the prob:

  host.Description.Behaviors.Add(metadataBehavior);

我真的不需要这个功能所以可以压缩它,但我仍然想知道为什么这会导致异常......(特别是在我合作伙伴的工作站上工作,所以我确定它必须这样做某处有一些设置")

I don't really need this feature so it's ok to squeeze it, but I still wonder why this was causing the Exception... (Especially that is is working on my partner's workstation, so I am sure it has to do with "some setting somewhere")

在其他项目上评论完全相同的台词也会使它们起作用,所以毫无疑问.

Commenting the exact same kind of line on other projects makes them work too, so there is no doubt left.

这篇关于WCF:运行服务器项目时出现 PlatformNotSupportedException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆