views:

7448

answers:

5

;Im writing a small WCF/WPF app to resize images but WCF is giving me grief when I try to send an image of size 28K to my service from the client. The service works fine when I send it smaller images. I immediately assumed that this was a configuration issue and I've trawled the web looking at posts regarding the MaxArrayLength property in my binding configuration. Ive upped the limits on these settings on both the client and server to the maximum 2147483647 but still I get the following error:

{"The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://mywebsite.com/services/servicecontracts/2009/01:OriginalImage. The InnerException message was 'There was an error deserializing the object of type System.Drawing.Image. The maximum array length quota (16384) has been exceeded while reading XML data. This quota may be increased by changing the MaxArrayLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader.'. Please see InnerException for more details."}

Ive made my client and server configs the same and they look like the following: Server:

<system.serviceModel>
    <bindings>
        <netTcpBinding>
            <binding name="NetTcpBinding_ImageResizerServiceContract" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
                hostNameComparisonMode="StrongWildcard" listenBacklog="10"
                maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="10"
                maxReceivedMessageSize="2147483647">
                <readerQuotas maxDepth="32"
                              maxStringContentLength="2147483647"
                              maxArrayLength="2147483647"
                              maxBytesPerRead="2147483647"
                              maxNameTableCharCount="2147483647" />
                <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
                <security mode="Transport">
                    <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
                    <message clientCredentialType="Windows" />
                </security>
            </binding>
        </netTcpBinding>
    </bindings>
    <behaviors>
        <serviceBehaviors>
            <behavior name="ServiceBehavior">
                <serviceMetadata httpGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <services>
        <service name="LogoResizer.WCF.ServiceTypes.ImageResizerService" behaviorConfiguration="ServiceBehavior">
            <host>
                <baseAddresses>
                    <add baseAddress="http://localhost:900/mex/"/&gt;
                    <add baseAddress="net.tcp://localhost:9000/" />
                </baseAddresses>
            </host>
            <endpoint binding="netTcpBinding" contract="LogoResizer.WCF.ServiceContracts.IImageResizerService" />
            <endpoint  address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        </service>
    </services>
</system.serviceModel>

and my client config looks like:

 <system.serviceModel>
    <bindings>
        <netTcpBinding>
            <binding name="NetTcpBinding_ImageResizerServiceContract" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
                hostNameComparisonMode="StrongWildcard" listenBacklog="10"
                maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="10"
                maxReceivedMessageSize="2147483647">
                <readerQuotas maxDepth="32" 
                              maxStringContentLength="2147483647"
                              maxArrayLength="2147483647" 
                              maxBytesPerRead="2147483647" 
                              maxNameTableCharCount="2147483647" />
                <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
                <security mode="Transport">
                    <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
                    <message clientCredentialType="Windows" />
                </security>
            </binding>
        </netTcpBinding>
    </bindings>
    <client>
        <endpoint address="net.tcp://localhost:9000/" binding="netTcpBinding"
            bindingConfiguration="NetTcpBinding_ImageResizerServiceContract"
            contract="ImageResizerService.ImageResizerServiceContract"
            name="NetTcpBinding_ImageResizerServiceContract">
            <identity>
                <userPrincipalName value="[email protected]" />
            </identity>
        </endpoint>
    </client>
</system.serviceModel>

It seems no matter what I set these values to I still get an error saying wcf cannot serialize my file because its greater than 16384. Any ideas?

edit: the email address in the userPrincipalName tag has been altered for my privacy

+10  A: 

My Bad - I forgot to apply my binding configuration to my endpoint in my server-side config. The server config should read:

<system.serviceModel>
 <bindings>
  <netTcpBinding>
   <binding name="NetTcpBinding_ImageResizerServiceContract" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
                hostNameComparisonMode="StrongWildcard" listenBacklog="10"
                maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="10"
                maxReceivedMessageSize="2147483647">
    <readerQuotas maxDepth="2147483647"
         maxStringContentLength="2147483647"
         maxArrayLength="2147483647"
         maxBytesPerRead="2147483647"
         maxNameTableCharCount="2147483647" />
    <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
    <security mode="Transport">
     <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
     <message clientCredentialType="Windows" />
    </security>
   </binding>

  </netTcpBinding>
 </bindings>
 <behaviors>
  <serviceBehaviors>
   <behavior name="ServiceBehavior">
    <serviceMetadata httpGetEnabled="true" />
    <serviceDebug includeExceptionDetailInFaults="false" />
   </behavior>
  </serviceBehaviors>
 </behaviors>
 <services>
  <service name="LogoResizer.WCF.ServiceTypes.ImageResizerService" behaviorConfiguration="ServiceBehavior">
   <host>
    <baseAddresses>
     <add baseAddress="http://localhost:900/mex/"/&gt;
     <add baseAddress="net.tcp://localhost:9000/" />
    </baseAddresses>
   </host>
   <endpoint bindingConfiguration="NetTcpBinding_ImageResizerServiceContract" binding="netTcpBinding" contract="LogoResizer.WCF.ServiceContracts.IImageResizerService" />
   <endpoint  address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
  </service>
 </services>
</system.serviceModel>

Note the bindingConfiguration="NetTcpBinding_ImageResizerServiceContract" has been added to the netTcp endpoint. My app now works with larger images. Sweet.

Dav Evans
I just beat my head on the desk for about 4 hours straight trying to solve this exact issue - same problem, the binding wasn't mapped correctly. Thanks!
GalacticCowboy
Helped me too. Thanks.
mark
A: 

Thank you, friend. I've been seeking for an answer for three days and I've not found anything clearly focused on adding bindingConfiguration. Besides, the same problem and consequently the same decision connected with wsDualHttpBinding configuration. It's really useful post.

A: 

Do you try to change maxArrayLength in the readerQuotas configuration of the client application??

Regards JEscalera

Jesús Escalera
A: 

I was struggling with the same issue for about ten ours. You save me from commiting suicide. Just kidding,

Thank you very much

gonzarodri
A: 

Please add the in binding. That is the main issue while uploading and downloading the byte[]. It solved my problem.

receiveTimeout="00:10:00">

Vijay