IBindingRuntimePreferences 介面

定義

定義選擇性合約,繫結可以實作此合約來指定服務要以同步還是非同步方式處理傳入要求。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) 服務模型執行時間層預設為使用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 服務模型執行時間層會檢查的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

取得值,這個值指出以同步還是非同步方式處理傳入要求可以比較有效率。Gets a value that indicates whether incoming requests can be handled more efficiently synchronously or asynchronously.

適用於