It has been a while since I last posted, but I haven't stopped working :) I am currently on a project involving WPF and WCF. While I am not a big fan of WPF, but I quite like WCF.
During the development of our project we run into a very annoying problem with WCF. After some help from Microsoft, we found a solution at last.
The problem is very easy to describe. On the one side, we have a WCF service running. On the other side, we have a client with a reference with to this service. Now and then, we need to update the service reference (because the service includes new features, for example). You can do this with svcutil or by right clicking on the reference in VisualStudio and choosing the "Update Service Reference" option.
One day, when updating the reference (with svcutil) we got this message:
Error: Cannot obtain Metadata from http://localhost:8000/businessservice/service/mex
The maximum nametable character count quota (16384) has been exceeded whilereading 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.
After several Google searches, I thought this could be solved by increasing the reader quotas parameters for the metadata exchange binding. This implied some minor changes in the service config file since the the mexBinding configuration section does not provide any properties: you have to use a wsHttpBinding without any security. This is explained here and Michele Leroux Bustamante (an expert on WCF) even provides a couple of samples (config-based sample here, and code-based sample here).
However, this did not help at all. Even setting the reader quotas to the maximum possible values made no difference at all. In the end, Microsoft told me what was wrong: the message refers to the svcutil reader quotas not the service ones! Svcutil has a limit on how much metadata it can read. This limit can be changed with a config file.
The solution is to create a config file for svcutil (see below) and place it in the same folder as the tool. Next time you run svcutil, the config file values will be taken into account.
<?xml version="1.0" encoding="utf-8"?>
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
<endpoint binding="customBinding" bindingConfiguration="MyBinding"
The MSDN WCF samples contain an example of creating this config file, although the main issue is a different one (how to configure svcutil to fetch metadata from a custom endpoint), so it wasn't so obvious to make the connection.
Technorati tags: WCF