首页 > 其他 > 详细

扩展方法检测客户端队列是否存在

时间:2014-10-29 12:27:18      阅读:206      评论:0      收藏:0      [点我收藏+]
public static class QeuedServiceHelper
    {
        public static void VerifyQeues()
        {
            Configuration config = ConfigurationManager.OpenExeConfiguration
                (ConfigurationUserLevel.None);
            ServiceModelSectionGroup  group=ServiceModelSectionGroup.GetSectionGroup(config);
            foreach(ChannelEndpointElement endPoint in group.Client.Endpoints )
            {
                if (endPoint.Binding == "netMsmqBinding")
                {
                    string queue = GetQueueFromUri(endPoint.Address);
                    if (MessageQueue.Exists(queue) == false)
                    {
                        MessageQueue.Create(queue);
                    }
                }
            }
        }
    }
}

使用ConfigurationManager提供了类型安全的方法来解析配置文件。它会加载WCF的配置数据(在ServiceModel     SectionGroup里),然后遍历所有的终结点。对于每个使用MSMQ绑定的终结点,VerifyQueue()会在必要时创建队列

 

以上方法也可以简化为:

            QeuedServiceHelper.VerifyQeues();
            MyContractClient proxy = new MyContractClient();
            proxy.MyMeThod();
            proxy.close();

应该注意的是客户端在发出队列调用之前调用QeuedServiceHelper.VerifyQeues(); 一次

扩展方法检测客户端队列是否存在

原文:http://www.cnblogs.com/running-mydream/p/4059012.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!