您所在的位置: 首页>>开发>>语言&工具>>

我的WCF之旅(12):使用MSMQ进行Reliable Messaging(4)

http://developer.51cto.com  2008-03-14 14:01  Artech  博客园  我要评论(0)
  • 摘要:在一个分布式的环境中,我们往往需要根据具体的情况采用不同的方式进行数据的传输。比如在一个Intranet内,我们一般通过TCP进行高效的数据通信;而在一个Internet的环境中,我们则通常使用Http进行跨平台的数据交换。
  • 标签:WCF  MSMQ  Reliable Messaging  Transaction

3、Hosting

Configuration

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<netMsmqBinding>
<binding name="msmqBinding">
<security>
<transport msmqAuthenticationMode="None"

msmqProtectionLevel="None" />
<message clientCredentialType="None" />
</security>
</binding>
</netMsmqBinding>
</bindings>
<services>
<service name="Artech.QueuedService.Service. OrderProcessorService">
<endpoint address="net.msmq://localhost/private/orders"

binding="netMsmqBinding"
bindingConfiguration="msmqBinding"

contract="Artech.QueuedService.Contract.IOrderProcessor" />
</service>
</services>
</system.serviceModel>
</configuration>

在默认的情况下,netMsmqBinding 的msmqAuthenticationMode为WindowsDomain,由于基于WindowsDomain必须安装AD,利于在本机模拟,我把msmqAuthenticationMode改为None,相应的ProtectionLevel和clientCredentialType改为None。

Program:

using System;
using System.Collections.Generic;
using System.Text;
using System.Messaging;
using System.ServiceModel;
using Artech.QueuedService.Service;

namespace Artech.QueuedService.Hosting
{
class Program
{
static void Main(string[] args)
{
string path = @".\private$\orders";
if(!MessageQueue.Exists(path))
{
MessageQueue.Create(path,true);
}

using (ServiceHost host = new ServiceHost(typeof(OrderProcessorService)))
{
host.Opened += delegate
{
Console.WriteLine("Service has begun to listen\n\n");
};

host.Open();

Console.Read();
}
}
}
}

在Host Service之前,通过MessageQueue.Create创建一个Message Queue,第二个参数为表明Queue是否支持Transaction的indicator,这里支持Transaction。

4、Client

Configuration

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<netMsmqBinding>
<binding name="msmqBinding">
<security>
<transport msmqAuthenticationMode="None"
msmqProtectionLevel="None" />
<message clientCredentialType="None" />
</security>
</binding>
</netMsmqBinding>
</bindings>
<client>
<endpoint address="net.msmq://localhost/private/orders"
binding="netMsmqBinding"
bindingConfiguration="msmqBinding"
contract="Artech.QueuedService.Contract.IOrderProcessor"
name="defaultEndpoint" />
</client>
</system.serviceModel>
</configuration>


共5页: 上一页 [1] [2] [3] 4 [5] 下一页
【内容导航】
WCF开发基础
深入Vista应用程序开发
走向银光 —— 一步一步学Silverlight2
让你的代码“炫”起来——WPF开发教程
WebSphere 实现SOA的利器
 
 验证码: (点击刷新验证码)   匿名发表
  • Visual C++ 完全自学宝典

  • 作者:强锋科技,朱洪波
  • Visual C++ 6.0是微软公司为程序人员提供的Visual Studio 6.0工具套件中的重要组成部分。本书由浅入深地介绍使用Visual C++ 6.0..
Copyright©2005-2008 51CTO.COM 版权所有