What is the maximum number of methods/operations that can be exposed via a single WCF Service Contract?
3 Answers
Although there is no maximum, you may run into issues with Metadata Exchange
- and the following config value and it's default: maxNameTableCharCount
.
Whilst attempting to add a new function to an existing functioning WCF Service
, I encountered errors whilst trying to "Update Service Reference" - relating to default value of maxNameTableCharCount
being too small to handle the size of the mex
transfer.
It is possible to override the default values for Metadata Exchange
by adding a custom mex binding
within the server config.
You may see an error message like below when you try to add or update your service reference if the config value is exceeded:
The maximum nametable character count quota (16384) has been exceeded while reading XML data. The nametable is a data structure used to store strings encountered during XML processing - long XML documents with non-repeating element names, attribute names and attribute values may trigger this quota. This quota may be increased by changing the MaxNameTableCharCount property on the XmlDictionaryReaderQuotas object used when creating the XML reader. Line 1, position 332845.
Server Mex endpoints should be specified as follows:
<endpoint address="mex"
binding="customBinding"
contract="IMetadataExchange"
name=""
bindingConfiguration="customMex"
listenUriMode="Explicit" />
With a Custom Binding block specified as follows:
<customBinding>
<binding name="customMex">
<textMessageEncoding>
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
</textMessageEncoding>
<httpTransport transferMode="Buffered" maxReceivedMessageSize="2147483647"
maxBufferSize="2147483647"/>
</binding>
</customBinding>
It may help if you're running into issues with lots of methods on a service.

- 22,205
- 9
- 65
- 83
-
1`mex` is used by the WCF tools in order to generate a proxy class for the client, but is never really used by the client itself. So why does the client config file need this binding added? – mcoolbeth Jun 29 '10 at 15:04
-
You're quite right, the client config doesn't require any corresponding config. I have modified the post now, thanks. – Tanner Jun 30 '10 at 09:36
-
I have not had any success following this method. I am using netTcp binding for my service. I have http disabled, and so I have specified tcpTransport instead of httpTransport. But this still fails when I have a large number of OperationContracts. Can anyone provide any input? – Jason Stevenson Apr 13 '11 at 21:13
-
How do you do this type of thing programmatically? – Alexandru Apr 01 '14 at 20:11
-
@Alexandru what type of thing exactly are you referring to? – Tanner Apr 05 '14 at 08:00
-
@Tanner How you set the reader quotas in the XAML, I'm wondering how you would do this to a programmatic binding created in C#... – Alexandru Apr 06 '14 at 19:20
-
@Alexandru this should help: http://stackoverflow.com/questions/969479/modify-endpoint-readerquotas-programatically – Tanner Apr 07 '14 at 07:47
There is no maximum. You can have as many as you wish, AFAIK.
However, whether or not it is practical is a different issue. It will become quite unwieldy if you have too many methods on a single contract.

- 73,706
- 19
- 184
- 253
The practical limit is probably no more than 10-12 methods. Any more than that and you're probably no longer describing the operations of a single component. I'd try really hard to refactor any component with dozens of operations down into multiple components.
That said, I'm sure there are exceptions!

- 6,625
- 1
- 29
- 64