0

私は WCF について学んでいて、単純な WCF の例に関するこの記事を見つけました。

次のコード (上記の記事から) ではSystem.ServiceModel.Dispatcher.ChannelDispatcher、 foreach ループ内に ? があるのに、なぜ を完全修飾する必要があるのusing System.ServiceModel;ですか? whileServiceHostが機能するために完全に修飾する必要はなく、 と同じ名前空間からのもの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); 
            }
        }
    }
}
4

1 に答える 1

4

ServiceHostSystem.ServiceModel 名前空間のクラスです (using ステートメントにあります)。ChannelDispatcherSystem.ServiceModel のクラスです。ディスパッチャーの名前空間。この using ステートメントを以下に追加すると、完全に修飾されていなくても ChannelDispatcher を使用できるようになります。

using System.ServiceModel.Dispatcher;
于 2012-06-27T21:25:53.583 に答える