Showing posts with label svc. Show all posts
Showing posts with label svc. Show all posts

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
    {
        // ...
    }
}
Web.Config:
<system.serviceModel>
    <services>
        <service name="SC.MessageGateway.WcfService.MailService">
            <endpoint address=""
                      binding="basicHttpBinding"
                      bindingConfiguration="LargeMessageSizeAndHttps"
                      contract="SC.MessageGateway.Communication.ServiceContracts.IMailService" />
        </service>
    </services>
    <behaviors>
        <serviceBehaviors>
            <behavior>
                <serviceMetadata httpGetEnabled="true"/>
                <serviceDebug includeExceptionDetailInFaults="false"/>
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <bindings>
        <basicHttpBinding>
            <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"/>
                </security>
            </binding>
        </basicHttpBinding>
    </bindings>
</system.serviceModel>
This answer was found with the help of Ladislav Mrnka's response in:
http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/a7ebf86b-7d47-43c8-84d0-f8be17d42ab9/