zoukankan      html  css  js  c++  java
  • 扩展方法检测客户端队列是否存在

    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(); 一次

  • 相关阅读:
    JDK动态代理
    回顾反射机制Method
    静态代理和动态代理
    使用jQuery实现ajax请求
    ajax函数
    事件 on
    函数2
    pytest-mock 调试实例
    Linux自启动tomcat
    第一次做性能测试
  • 原文地址:https://www.cnblogs.com/running-mydream/p/4059012.html
Copyright © 2011-2022 走看看