WCF各种banding支持的类型

 static void PrintInfo()
        {
            Module[] mods = Assembly.LoadWithPartialName("System.ServiceModel").GetModules();
            List<Binding> allBinding = new List<Binding>();
            Console.WriteLine("WCF定制的绑定类型:");
            foreach (Module mod in mods)
            {
                foreach (Type type in mod.GetTypes())
                {
                    if (type.Name.EndsWith("Binding"))
                    {
                        //此处需把CustomBinding排除在外,因为其建立之后必须制定信道范型 
                        if (type.IsClass && !type.IsAbstract && type.Name != "CustomBinding")
                        {
                            //因要调用绑定的无参构造函数,所以必须先判定绑定类型是否存在无参构造函数 
                            var ctor = type.GetConstructor(new Type[] { });
                            if (ctor != null)
                            {
                                allBinding.Add((Binding)Activator.CreateInstance(type));
                                Console.WriteLine("   " + type.Name);
                            }
                        }
                    }
                }
            }

            Console.WriteLine("各个定制绑定类型对信道范型的支持:");
            foreach (Binding binding in allBinding)
            {
                Console.WriteLine(" " + binding.Name);
                Dictionary<string, bool> result = ChannelsOfBinding(binding);
                foreach (KeyValuePair<string, bool> KeyValue in result)
                {
                    if (KeyValue.Value)
                    {
                        Console.WriteLine("   {0,-8}:  {1}", "Listener", KeyValue.Key.ToString());
                    }
                }
                Dictionary<string, bool> factoryResult = ChannelsOfBindingFactory(binding);
                foreach (KeyValuePair<string, bool> KeyValue in factoryResult)
                {
                    if (KeyValue.Value)
                    {
                        Console.WriteLine("   {0,-8}:  {1}", "Factory", KeyValue.Key.ToString());
                    }
                }
            }  
        }

        /// <summary> 
        /// 获取绑定类型对各个信道工厂的支持 
        /// </summary> 
        /// <param name="binding"></param> 
        /// <returns></returns> 
        static Dictionary<string, bool> ChannelsOfBindingFactory(Binding binding)
        {
            Dictionary<string, bool> channelsList = new Dictionary<string, bool>();
            channelsList.Add("IInputChannel", binding.CanBuildChannelFactory<IInputChannel>());
            channelsList.Add("IInputSessionChannel", binding.CanBuildChannelFactory<IInputSessionChannel>());
            channelsList.Add("IOutputChannel", binding.CanBuildChannelFactory<IOutputChannel>());
            channelsList.Add("IOutputSessionChannel", binding.CanBuildChannelFactory<IOutputSessionChannel>());
            channelsList.Add("IDuplexChannel", binding.CanBuildChannelFactory<IDuplexChannel>());
            channelsList.Add("IDuplexSessionChannel", binding.CanBuildChannelFactory<IDuplexSessionChannel>());
            channelsList.Add("IDuplexContextChannel", binding.CanBuildChannelFactory<IDuplexContextChannel>());
            channelsList.Add("IReplyChannel", binding.CanBuildChannelFactory<IReplyChannel>());
            channelsList.Add("IReplySessionChannel", binding.CanBuildChannelFactory<IReplySessionChannel>());
            channelsList.Add("IRequestChannel", binding.CanBuildChannelFactory<IRequestChannel>());
            channelsList.Add("IRequestSessionChannel", binding.CanBuildChannelFactory<IRequestSessionChannel>());
            return channelsList;

        }
        /// <summary> 
        /// 获取绑定类型对各个信道监听器的支持 
        /// </summary> 
        /// <param name="binding"></param> 
        /// <returns></returns> 
        static Dictionary<string, bool> ChannelsOfBinding(Binding binding)
        {
            Dictionary<string, bool> channelsList = new Dictionary<string, bool>();
            channelsList.Add("IInputChannel", binding.CanBuildChannelListener<IInputChannel>());
            channelsList.Add("IInputSessionChannel", binding.CanBuildChannelListener<IInputSessionChannel>());
            channelsList.Add("IOutputChannel", binding.CanBuildChannelListener<IOutputChannel>());
            channelsList.Add("IOutputSessionChannel", binding.CanBuildChannelListener<IOutputSessionChannel>());
            channelsList.Add("IDuplexChannel", binding.CanBuildChannelListener<IDuplexChannel>());
            channelsList.Add("IDuplexSessionChannel", binding.CanBuildChannelListener<IDuplexSessionChannel>());
            channelsList.Add("IDuplexContextChannel", binding.CanBuildChannelListener<IDuplexContextChannel>());
            channelsList.Add("IReplyChannel", binding.CanBuildChannelListener<IReplyChannel>());
            channelsList.Add("IReplySessionChannel", binding.CanBuildChannelListener<IReplySessionChannel>());
            channelsList.Add("IRequestChannel", binding.CanBuildChannelListener<IRequestChannel>());
            channelsList.Add("IRequestSessionChannel", binding.CanBuildChannelListener<IRequestSessionChannel>());
            return channelsList;

        } 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值