Tuesday, September 6, 2011

WCF using svc files in IIS and the maximum message size quota exceeded error

When using WCF you can (and will ;) ) run into the following exception when posting messages:
The maximum message size quota for incoming messages (65536) has been exceeded.
Normally you can easily edit the config files and bind the right endpoint to the right bindingconfiguration and it workt. But how can you do that when using wcf by calling svc files hosted on an IIS server which have no endpoint configured. I've been struggling with this for hours and I can finally give you the answer! You'll have to match the service name with the full classname (including) namespace. After that you can setup the max length and for example ssl (https support). MailService.svc.cs:
namespace SC.MessageGateway.WcfService
    public class MailService : IMailService
        // ...
        <service name="SC.MessageGateway.WcfService.MailService">
            <endpoint address=""
                      contract="SC.MessageGateway.Communication.ServiceContracts.IMailService" />
                <serviceMetadata httpGetEnabled="true"/>
                <serviceDebug includeExceptionDetailInFaults="false"/>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
            <binding name="LargeMessageSizeAndHttps" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
                <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
                <!-- Enable Https -->
                <security mode="Transport">
                    <message clientCredentialType="Certificate"/>
This answer was found with the help of Ladislav Mrnka's response in: