c# - 为什么System.ServiceModel.Dispatcher需要全限定才能编译

标签 c# wcf .net-4.0 namespaces

我正在学习 WCF 并找到了 this article在一个简单的 WCF 示例中。

在下面的代码中(来自上面的文章),为什么System.ServiceModel.Dispatcher.ChannelDispatcher在 foreach 循环中需要完全限定时出现 using System.ServiceModel; ?虽然 ServiceHost不需要完全限定它就可以工作并且它来自与 Dispatcher 相同的命名空间.

如果删除 System.ServiceModel来自 System.ServiceModel.Dispatcher.ChannelDispatcher在循环中,代码无法编译。

using System;
using System.ServiceModel;

namespace ConsoleHost
{
    class Program
    {
        static void Main(string[] args)
        {
            Type serviceType = typeof(EmailService.EmailValidator);
            Uri serviceUri = new Uri("http://localhost:8080/");

            ServiceHost host = new ServiceHost(serviceType, serviceUri);
            host.Open();

            foreach (System.ServiceModel.Dispatcher.ChannelDispatcher dispatcher in host.ChannelDispatchers)
            {
                Console.WriteLine("\t{0}, {1}", dispatcher.Listener.Uri.ToString(), dispatcher.BindingName); 
            }
        }
    }
}

最佳答案

ServiceHost是 System.ServiceModel 命名空间上的一个类(在 using 语句中); ChannelDispatcher是 System.ServiceModel 上的一个类。 调度员 命名空间。如果您在下面添加此 using 语句,您将能够使用 ChannelDispatcher 而无需完全限定。

using System.ServiceModel.Dispatcher;

关于c# - 为什么System.ServiceModel.Dispatcher需要全限定才能编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11234934/

相关文章:

c# - 手动设置服务引用的命名空间

.net - 适用于 .NET 3.5(或 4.0)的优秀 XMPP/Jabber 客户端库

c# - 比较两个大型通用列表

c# - 需要具有 .NET 4.0 新功能的单一生产者/单一消费者模式示例

c# - Word VSTO 覆盖 CTRL+Z/CTRL+Y

c# - 在 RX 中迭代从 IGroupedObservable 中选择的 IEnumerable

c# - 与多个从站通信(基于 Modbus 协议(protocol))

C# Java 命名管道稳定性

c# - 无法将 MemoryStream 参数传递给 WCF 方法?

wcf - 通过 .config 文件设置自定义 WCF 绑定(bind)行为 - 为什么这不起作用?