IBindingRuntimePreferences IBindingRuntimePreferences IBindingRuntimePreferences IBindingRuntimePreferences Interface

定义

定义可选的协定,绑定通过实现该协定,可以指定传入请求是由服务同步处理还是异步处理。Defines the optional contract that a binding can implement to specify whether incoming requests are handled synchronously or asynchronously by the service.

public interface class IBindingRuntimePreferences
public interface IBindingRuntimePreferences
type IBindingRuntimePreferences = interface
Public Interface IBindingRuntimePreferences
派生

示例

下面的示例演示实现 IBindingRuntimePreferences 接口的绑定是如何实现的。The following example shows the implementation of a binding that implements the IBindingRuntimePreferences interface. 此代码摘自分块通道示例:This code is taken from the Chunking Channel sample:

public class TcpChunkingBinding : Binding, IBindingRuntimePreferences
{
    TcpTransportBindingElement tcpbe;
    ChunkingBindingElement be;
    public TcpChunkingBinding()
        : base()
    {
        Initialize();

    }
    public TcpChunkingBinding(string name, string ns)
        : base(name, ns)
    {
        Initialize();
    }
    public override BindingElementCollection CreateBindingElements()
    {
        BindingElementCollection col = new BindingElementCollection();
        col.Add(be);
        col.Add(tcpbe);
        return col;
    }

    public override string Scheme
    {
        get { return tcpbe.Scheme;  }
    }
    public int MaxBufferedChunks
    {
        get { return this.be.MaxBufferedChunks; }
        set { this.be.MaxBufferedChunks = value; }
    }

    void Initialize()
    {
         be = new ChunkingBindingElement();
         tcpbe = new TcpTransportBindingElement();
        tcpbe.TransferMode=TransferMode.Buffered; //no transport streaming
        tcpbe.MaxReceivedMessageSize = ChunkingUtils.ChunkSize + 100 * 1024; //add 100KB for headers
         this.SendTimeout = new TimeSpan(0, 5, 0);
         this.ReceiveTimeout = this.SendTimeout;

    }

    #region IBindingRuntimePreferences Members
    public bool ReceiveSynchronously
    {
        get { return true; }
    }
    #endregion
}

注解

在某些情况下,绑定使用同步 ReceiveRequest 方法处理消息可能更加有效。In some cases it may be more efficient for a binding to process messages with the synchronous Receive or Request methods. Binding 类可以选择实现 IBindingRuntimePreferences,从而指示调用方这是优先选择。A Binding class can optionally implement IBindingRuntimePreferences to indicate to callers that this is preferred.

如果绑定不实现IBindingRuntimePreferences,Windows Communication Foundation (WCF) Service Model Runtime 层默认使用的异步版本ReceiveRequest方法。If a binding does not implement IBindingRuntimePreferences, the Windows Communication Foundation (WCF) Service Model Runtime layer defaults to using the asynchronous versions of the Receive and Request methods. 如果绑定实现IBindingRuntimePreferences,WCF Service Model Runtime 层会检查的值ReceiveSynchronously,并使用其确定是否需要调用同步版本的这些方法 (ReceiveRequest) 或异步版本 (BeginReceiveEndReceive(IAsyncResult)BeginRequestEndRequest(IAsyncResult)If a binding does implement IBindingRuntimePreferences, the WCF Service Model Runtime layer checks the value of ReceiveSynchronously and uses that to determine whether to call the synchronous versions of the these methods (Receive or Request) or the asynchronous versions (BeginReceive and EndReceive(IAsyncResult) or BeginRequest and EndRequest(IAsyncResult). 如果绑定实现 IBindingRuntimePreferences 并从 true 属性返回 ReceiveSynchronously,则建议使用同步的 ReceiveRequest 方法从通道接收消息。If IBindingRuntimePreferences is implemented by the binding and returns true from the ReceiveSynchronously property, it is recommended that you use the synchronous Receive and Request methods to receive messages from the channel. 如果绑定不实现 IBindingRuntimePreferences,或从 false 属性返回 ReceiveSynchronously,则建议使用异步的 BeginReceiveEndReceive(IAsyncResult)BeginRequestEndRequest(IAsyncResult) 方法。If the binding does not implement IBindingRuntimePreferences or returns false from the ReceiveSynchronously property, it is recommended that you use the asynchronous BeginReceive and EndReceive(IAsyncResult) or BeginRequest and EndRequest(IAsyncResult) methods.

无论 ReceiveSynchronously 属性返回什么值,所有绑定仍然必须为所实现的特定通道类型提供 Receive 方法同步版本和异步版本的有效实现。Regardless of the value returned by the ReceiveSynchronously property, all bindings must still provide valid implementations of both the synchronous and asynchronous versions of the Receive methods for the specific channel types implemented. 有关实现自定义通道的详细信息,请参阅开发通道For more information about implementing custom channels, see Developing Channels.

属性

ReceiveSynchronously ReceiveSynchronously ReceiveSynchronously ReceiveSynchronously

获取一个值,该值指示传入请求是由同步处理更加有效还是异步处理更加有效。Gets a value that indicates whether incoming requests can be handled more efficiently synchronously or asynchronously.

适用于