Export (0) Print
Expand All

IBindingRuntimePreferences Interface

Defines the optional contract that a binding can implement to specify whether incoming requests are handled synchronously or asynchronously by the service.

Namespace:  System.ServiceModel.Channels
Assembly:  System.ServiceModel (in System.ServiceModel.dll)

public interface IBindingRuntimePreferences

The IBindingRuntimePreferences type exposes the following members.

  NameDescription
Public propertyReceiveSynchronouslyGets a value that indicates whether incoming requests can be handled more efficiently synchronously or asynchronously.
Top

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 the 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.

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
}

.NET Framework

Supported in: 4.5.3, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft