Esempio n. 1
0
        /// <summary>
        /// 初始化新建一个 <see cref="SingleRemoteObject"/> 类的实例对象。
        /// </summary>
        /// <param name="target">待发送的目标地址。</param>
        /// <param name="source">接受监听的地址路径。</param>
        /// <exception cref="System.ArgumentNullException">
        /// target
        /// or
        /// source
        /// </exception>
        public SingleRemoteObject(string target, string source)
        {
            if (string.IsNullOrEmpty(target))
            {
                throw new ArgumentNullException("target");
            }
            if (string.IsNullOrEmpty(source))
            {
                throw new ArgumentNullException("source");
            }

            _source = MessageProxyCreater.CreateLocalQueue(source);
            _target = MessageProxyCreater.CreateRemoteQueue(target);
        }
Esempio n. 2
0
        /// <summary>
        /// 向远程对象发送消息。
        /// </summary>
        /// <param name="msg">待发送的消息对象。</param>
        public void Send(Message msg)
        {
            var obj = new System.Messaging.Message();

            obj.Body      = msg;
            obj.Formatter = new XmlMessageFormatter(new Type[] { typeof(Message) });

            var data = Clients.Select(p => MessageProxyCreater.CreateRemoteQueue(string.Format(_template, p)));

            foreach (var item in data)
            {
                item.Send(obj, Environment.MachineName);
            }
        }