NetMsmqBinding 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示适用于跨计算机通信的排队绑定。
public ref class NetMsmqBinding : System::ServiceModel::MsmqBindingBase
public class NetMsmqBinding : System.ServiceModel.MsmqBindingBase
type NetMsmqBinding = class
inherit MsmqBindingBase
Public Class NetMsmqBinding
Inherits MsmqBindingBase
- 继承
示例
下面的示例演示如何将服务配置为使用 NetMsmqBinding 绑定。
首先演示的是配置文件。
接下来演示的是实际服务代码。
// Define a service contract.
[ServiceContract(Namespace="http://Microsoft.ServiceModel.Samples")]
public interface IQueueCalculator
{
[OperationContract(IsOneWay=true)]
void Add(double n1, double n2);
[OperationContract(IsOneWay = true)]
void Subtract(double n1, double n2);
[OperationContract(IsOneWay = true)]
void Multiply(double n1, double n2);
[OperationContract(IsOneWay = true)]
void Divide(double n1, double n2);
}
' Define a service contract.
<ServiceContract(Namespace:="http://Microsoft.ServiceModel.Samples")> _
Public Interface IQueueCalculator
<OperationContract(IsOneWay:=True)> _
Sub Add(ByVal n1 As Double, ByVal n2 As Double)
<OperationContract(IsOneWay := True)> _
Sub Subtract(ByVal n1 As Double, ByVal n2 As Double)
<OperationContract(IsOneWay := True)> _
Sub Multiply(ByVal n1 As Double, ByVal n2 As Double)
<OperationContract(IsOneWay := True)> _
Sub Divide(ByVal n1 As Double, ByVal n2 As Double)
End Interface
// Service class that implements the service contract.
// Added code to write output to the console window
public class CalculatorService : IQueueCalculator
{
[OperationBehavior]
public void Add(double n1, double n2)
{
double result = n1 + n2;
Console.WriteLine("Received Add({0},{1}) - result: {2}", n1, n2, result);
}
[OperationBehavior]
public void Subtract(double n1, double n2)
{
double result = n1 - n2;
Console.WriteLine("Received Subtract({0},{1}) - result: {2}", n1, n2, result);
}
[OperationBehavior]
public void Multiply(double n1, double n2)
{
double result = n1 * n2;
Console.WriteLine("Received Multiply({0},{1}) - result: {2}", n1, n2, result);
}
[OperationBehavior]
public void Divide(double n1, double n2)
{
double result = n1 / n2;
Console.WriteLine("Received Divide({0},{1}) - result: {2}", n1, n2, result);
}
}
' Service class that implements the service contract.
' Added code to write output to the console window
Public Class CalculatorService
Implements IQueueCalculator
<OperationBehavior> _
Public Sub Add(ByVal n1 As Double, ByVal n2 As Double) Implements IQueueCalculator.Add
Dim result As Double = n1 + n2
Console.WriteLine("Received Add({0},{1}) - result: {2}", n1, n2, result)
End Sub
<OperationBehavior> _
Public Sub Subtract(ByVal n1 As Double, ByVal n2 As Double) Implements IQueueCalculator.Subtract
Dim result As Double = n1 - n2
Console.WriteLine("Received Subtract({0},{1}) - result: {2}", n1, n2, result)
End Sub
<OperationBehavior> _
Public Sub Multiply(ByVal n1 As Double, ByVal n2 As Double) Implements IQueueCalculator.Multiply
Dim result As Double = n1 * n2
Console.WriteLine("Received Multiply({0},{1}) - result: {2}", n1, n2, result)
End Sub
<OperationBehavior> _
Public Sub Divide(ByVal n1 As Double, ByVal n2 As Double) Implements IQueueCalculator.Divide
Dim result As Double = n1 / n2
Console.WriteLine("Received Divide({0},{1}) - result: {2}", n1, n2, result)
End Sub
End Class
// This is the hosting application. This code can appear directly in the service class as well.
class HostApp
{
// Host the service within this EXE console application.
public static void Main()
{
// Get MSMQ queue name from appsettings in configuration.
string queueName = ConfigurationManager.AppSettings["queueName"];
// Create the transacted MSMQ queue if necessary.
if (!MessageQueue.Exists(queueName))
MessageQueue.Create(queueName, true);
// Get the base address that is used to listen for WS-MetaDataExchange requests.
// This is useful to generate a proxy for the client.
string baseAddress = ConfigurationManager.AppSettings["baseAddress"];
// Create a ServiceHost for the CalculatorService type.
using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), new Uri(baseAddress)))
{
// Open the ServiceHostBase to create listeners and start listening for messages.
serviceHost.Open();
// The service can now be accessed.
Console.WriteLine("The service is ready.");
Console.WriteLine("Press <ENTER> to terminate service.");
Console.WriteLine();
Console.ReadLine();
// Close the ServiceHostBase to shutdown the service.
serviceHost.Close();
}
}
}
' This is the hosting application. This code can appear directly in the service class as well.
Friend Class HostApp
' Host the service within this EXE console application.
Public Shared Sub Main()
' Get MSMQ queue name from appsettings in configuration.
Dim queueName As String = ConfigurationManager.AppSettings("queueName")
' Create the transacted MSMQ queue if necessary.
If (Not MessageQueue.Exists(queueName)) Then
MessageQueue.Create(queueName, True)
End If
' Get the base address that is used to listen for WS-MetaDataExchange requests.
' This is useful to generate a proxy for the client.
Dim baseAddress As String = ConfigurationManager.AppSettings("baseAddress")
' Create a ServiceHost for the CalculatorService type.
Using serviceHost As New ServiceHost(GetType(CalculatorService), New Uri(baseAddress))
' Open the ServiceHostBase to create listeners and start listening for messages.
serviceHost.Open()
' The service can now be accessed.
Console.WriteLine("The service is ready.")
Console.WriteLine("Press <ENTER> to terminate service.")
Console.WriteLine()
Console.ReadLine()
' Close the ServiceHostBase to shutdown the service.
serviceHost.Close()
End Using
End Sub
End Class
注解
NetMsmqBinding 绑定通过利用消息队列 (MSMQ) 作为传输来提供队列支持,并且为松耦合应用程序、故障隔离、负载均衡和断开连接的操作提供支持。 有关这些功能的讨论,请参阅 队列概述。
这是由 Windows Communication Foundation (WCF) 提供的系统提供的绑定之一。 建议的过程是使用配置值定义绑定而不是使用基于代码的方法,除了必须将配置值设为已初始化的服务的某些高级方案之外。
构造函数
NetMsmqBinding() |
初始化 NetMsmqBinding 类的新实例。 |
NetMsmqBinding(NetMsmqSecurityMode) |
使用指定的安全模式初始化 NetMsmqBinding 类的新实例。 |
NetMsmqBinding(String) |
从指定配置绑定元素的设置中初始化 NetMsmqBinding 类的新实例。 |
属性
CloseTimeout |
获取或设置在传输引发异常之前可用于关闭连接的时间间隔。 (继承自 Binding) |
CustomDeadLetterQueue |
获取或设置一个 URI,该 URI 包含每个应用程序的死信队列(该队列用于放置已过期的消息以及传输或传递失败的消息)的位置。 (继承自 MsmqBindingBase) |
DeadLetterQueue |
获取或设置一个枚举值,该值指示要使用的死信队列的类型。 (继承自 MsmqBindingBase) |
Durable |
获取或设置一个值,该值指定此绑定处理的消息是持久的还是可变的。 (继承自 MsmqBindingBase) |
EnvelopeVersion |
获取此绑定处理的消息将要使用的 SOAP 版本。 |
ExactlyOnce |
获取或设置一个值,该值指示是否只接收一次由此绑定处理的消息。 (继承自 MsmqBindingBase) |
MaxBufferPoolSize |
获取或设置为从通道接收消息的消息缓冲区管理器分配并供其使用的最大内存量。 |
MaxReceivedMessageSize |
获取或设置此绑定可处理消息的最大字节大小。 (继承自 MsmqBindingBase) |
MaxRetryCycles |
获取或设置尝试向接收应用程序传递消息的最大重试周期数。 (继承自 MsmqBindingBase) |
MessageVersion |
获取由绑定所配置的客户端和服务使用的消息版本。 (继承自 Binding) |
Name |
获取或设置绑定的名称。 (继承自 Binding) |
Namespace |
获取或设置绑定的 XML 命名空间。 (继承自 Binding) |
OpenTimeout |
获取或设置在传输引发异常之前可用于打开连接的时间间隔。 (继承自 Binding) |
QueueTransferProtocol |
获取或设置一个枚举值,该值指示此绑定使用的排队信道传输。 |
ReaderQuotas |
获取或设置与此绑定关联的 XmlDictionaryReaderQuotas。 |
ReceiveContextEnabled |
获取或设置一个指示是否请求接收上下文行为的值。 (继承自 MsmqBindingBase) |
ReceiveErrorHandling |
获取或设置一个枚举值,该值指定如何处理病毒消息。 (继承自 MsmqBindingBase) |
ReceiveRetryCount |
获取或设置从应用程序队列读取的消息的最大立即传递尝试次数。 (继承自 MsmqBindingBase) |
ReceiveTimeout |
获取或设置连接在撤消之前保持非活动状态的最大时间间隔,在此时间间隔内未接收任何应用程序消息。 (继承自 Binding) |
RetryCycleDelay |
获取或设置一个值,该值指示尝试传递无法立即传递的消息时,各个重试周期之间的时间延迟。 (继承自 MsmqBindingBase) |
Scheme |
返回此绑定的方案。 (继承自 MsmqBindingBase) |
Security |
获取或设置与此绑定关联的 NetMsmqSecurity。 |
SendTimeout |
获取或设置在传输引发异常之前可用于完成写入操作的时间间隔。 (继承自 Binding) |
TimeToLive |
获取或设置一个时间间隔,该时间间隔指示此绑定处理的消息在过期之前可以保留在队列中的时间长度。 (继承自 MsmqBindingBase) |
UseActiveDirectory |
获取或设置一个值,该值指示是否应该使用 Active Directory 来转换队列地址。 |
UseMsmqTracing |
获取或设置一个值,该值指示是否应跟踪由此绑定处理的消息。 (继承自 MsmqBindingBase) |
UseSourceJournal |
获取或设置一个值,该值指示是否应将此绑定处理的消息副本存储到源日记队列中。 (继承自 MsmqBindingBase) |
ValidityDuration |
获取或设置一个值,该值指定由接收上下文功能锁定消息的持续时间。 (继承自 MsmqBindingBase) |
方法
显式接口实现
IBindingRuntimePreferences.ReceiveSynchronously |
获取一个值,该值指示传入请求是由同步处理更加有效还是异步处理更加有效。 (继承自 MsmqBindingBase) |