我正在学习 WCF,并在一个简单的 WCF 示例中找到了这篇文章。
在下面的代码中(来自上面的文章),为什么System.ServiceModel.Dispatcher.ChannelDispatcher
在 foreach 循环中有 a 时需要完全限定using System.ServiceModel;
?虽然ServiceHost
不需要完全限定它才能工作,并且它来自与Dispatcher
.
如果您在循环中删除System.ServiceModel
from 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);
}
}
}
}