Configuring the Client Endpoint for svcutil

One of the more common questions I get is along these lines:

I want to configure svcutil to use a particular binding. How do I do that?

Usually, this happens for one of two reasons:

1) You’ve exposed your metadata with a secure binding, and need a way to generate proxy from it.

2) The size of your metadata is too large for svcutil’s defaults.

In both these cases, you usually get a non-descript error message from svcutil:

Error: Cannot obtain Metadata from https://localhost/

If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at https://go.microsoft.com/fwlink/?LinkId=65455.

WS-Metadata Exchange Error

URI: https://localhost/

Metadata contains a reference that cannot be resolved: 'https://localhost/mex.

There is an error in XML document (1, 120595).

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

The way to fix these issues is to locate your copy of svcutil.exe (usually under C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin), create a file called svcutil.exe.config and add configuration just like you would configure a client endpoint.

For example, to use an http binding that has the maximum value for each quota, copy the following XML into your svcutil.exe.config

<?xml version="1.0" encoding="utf-8"?>

<configuration>

<system.serviceModel>

<bindings>

<customBinding>

<binding name="MaxQuotasBinding">

<textMessageEncoding>

<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />

</textMessageEncoding>

<httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" />

</binding>

</customBinding>

</bindings>

<client>

<endpoint binding="customBinding" bindingConfiguration="MaxQuotasBinding" contract="IMetadataExchange" name="http" />

</client>

</system.serviceModel>

</configuration>

Of course, the same method can be used to change the type of binding you want to use (named pipes, tcp, etc…) and to configure your binding with security.

Comments