Editare

Partajați prin


IBindingRuntimePreferences Interface

Definition

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
Derived

Examples

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
}

Remarks

In some cases it may be more efficient for a binding to process messages with the synchronous Receive or Request methods. A Binding class can optionally implement IBindingRuntimePreferences to indicate to callers that this is preferred.

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. 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 these methods (Receive or Request) or the asynchronous versions (BeginReceive and EndReceive(IAsyncResult) or BeginRequest and EndRequest(IAsyncResult)). 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. 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.

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.

Properties

ReceiveSynchronously

Gets a value that indicates whether incoming requests can be handled more efficiently synchronously or asynchronously.

Applies to