I’m learning about WCF and found this article on a simple WCF example.
In the following code (from the above article), why does the System.ServiceModel.Dispatcher.ChannelDispatcher in the foreach loop need to be fully qualified when there is a using System.ServiceModel;? While ServiceHost doesn’t need to be fully qualified for it to work and it is from the same namespace as Dispatcher.
If you remove the System.ServiceModel from System.ServiceModel.Dispatcher.ChannelDispatcher in the loop the code doesn’t compile.
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);
}
}
}
}
ServiceHostis a class on the System.ServiceModel namespace (which you have in the using statements);ChannelDispatcheris a class on the System.ServiceModel.Dispatcher namespace. If you add this using statement below, you’ll be able to use ChannelDispatcher without being fully-qualified.