WCF Tips: Achieving High Performance. List of Key Design Decisions and Tuning Parameters






When working with WCF especially when middle-tier client applications uses Windows Communication Foundation, you sould always think about performance and take some major design decisions and tuning parameters.

  1. WCF client not generated as a proxy via SvcUtil.exe (Relevant more in .NET 3.0. In .NET 3.5 major performance improvement was made on WCF proxy creation).
    • Client shares service contract and schema (model classes as data contract).
    • Cache WCF proxy as a static member
      • One instance, once instance only, ever
      • Still thread-safe based on WCF under-the-covers network connection pool management
        Channels created directly via ChannelFactory
      • Hidden static channel exposed as a property
      • Getter/Setter logic does all initialization/abort/recreation as necessary
      • Maintains clean code in use of service operations
    • Expect up to 50% perfdegradation if you instance a generated proxy client class per Web Service call
      • Very different than ASMX
      • Same client caching approach in ASMX: no performance difference
  2. Static WCF Channel Logic code example:

private static object _channelLock= new object();

private static ChannelFactory<IMyService> _factory;

private static IMyService _channel;


public IMyService Channel




IMyService localChannel = _channel;


if (localChannel == null)


lock (_channelLock)


if (_factory == null)


EndpointAddress remoteNodeEndPointAddress= new EndpointAddress(“[someURI]”);

_factory = new ChannelFactory<IMyService>(“BasicHttpBindingMyServices”, remoteNodeEndPointAddress);



if (_channel == null)


_channel = _factory.CreateChannel();



return _channel;




return localChannel;




lock (_channelLock)


if (((IChannel)_channel).State != CommunicationState.Opened)



_channel = null;


if (_factory.State!= CommunicationState.Opened)



_factory = null;






Service Operations Call (instanced per call):

public string SampleCall(string message)




return this.Channel.SampleCall(message);




this.Channel = null;





Now lets see some important Tuning Parameters:

  • Tcp binding is a custom binding, with binary encoding:


<binding name=”CustomTcpBinding_PrimaryTradeServices”>

<binaryMessageEncoding maxReadPoolSize=”64″ maxWritePoolSize=”32″ maxSessionSize=”4096″>

<readerQuotas maxDepth=”64″ maxStringContentLength=”131072″ maxArrayLength=”16384″

maxBytesPerRead=”16384″ maxNameTableCharCount=”32768″/>


<tcpTransport manualAddressing=”false” maxBufferPoolSize=”524288″ maxReceivedMessageSize=”524288″

connectionBufferSize=”65536″ hostNameComparisonMode=”StrongWildcard”

channelInitializationTimeout=”00:00:05″ maxBufferSize=”524288″

maxPendingConnections=”100″ maxOutputDelay=”00:00:00.2000000″

maxPendingAccepts=”100″ transferMode=”Buffered” listenBacklog=”400″

portSharingEnabled=”false” teredoEnabled=”false”>

<connectionPoolSettings groupName=”default” leaseTimeout=”00:05:00″ idleTimeout=”00:02:00″





  • .exe.config: For self-host service hosts (not for IIS-hosted services)





  • For ASP.NET Worker Process (single worker process):All options off (worker process recycle off, rapid fail protection off)
  • For Service Implementation use: [ServiceBehavior(ConcurrencyMode= ConcurrencyMode.Multiple, InstanceContextMode= InstanceContextMode.PerCall)]
  • In .config file for Service –Uses custom WCF behavior to set throttles higher

<behavior name=”TradeServiceBehaviors”>

<serviceDebug httpHelpPageEnabled=”true” includeExceptionDetailInFaults=”true”/>

<serviceMetadata httpGetEnabled=”true” httpGetUrl=””/>

<serviceThrottling maxConcurrentInstances=”400″ maxConcurrentCalls=”400″/>


Well I hope these Design Decisions and Tuning Parameters will help you Building Interoperable, High-Performance Systems with Windows Communication Foundation (WCF).


I discover these great WCF tips when investigating MS “Service-Orientation Case Study” – The .NET StockTrader Application


Rotem Bloom

此条目发表在Best Practices分类目录。将固定链接加入收藏夹。

One Response to WCF Tips: Achieving High Performance. List of Key Design Decisions and Tuning Parameters

  1. dor cohen说道:

    Hi my loved one! I want to say that this article is amazing, great written and come with almost all vital infos. I’d like to see more posts like this.


Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  更改 )

Google+ photo

You are commenting using your Google+ account. Log Out /  更改 )

Twitter picture

You are commenting using your Twitter account. Log Out /  更改 )

Facebook photo

You are commenting using your Facebook account. Log Out /  更改 )


Connecting to %s