Passing a byte array to a WCF method from Silverlight – The remote server returned an error: NotFound

5

Posted by Joe | Posted in Silverlight | Posted on 03-06-2009

My Silverlight application calls a method to get an image from the server as a byte array. When adding my Service Reference the ServiceReferences.ClientConfig automatically generated the binding’s MaxBufferSize and MaxRecievedMessageSize as 2147483647 which is a lot bigger than I want to I changed them to 5242880 (5MB).  When the application calls the service to bring down an image these values are used to limit the size of the response message.

I also set the MaxBufferSize and MaxRecievedMessageSize to 5242880 in the web.config file of the web application hosting my service.  At this point when I call the method in my service to upload an image passing a byte array I get a The remote server returned an error: NotFound error message, which really isn’t very helpful.

In this instance the problem is that the maximum array length for the XML reader has been exceeded. This can be fixed by expanding the binding section to insert a readerQuotas section and increase the maxArrayLength.

<services>
    <service behaviorConfiguration="GalleryServiceBehavior" name="GalleryService.GalleryService">
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttpLargeMessage" contract="GalleryService.IGalleryService" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    </service>
</services>

<bindings>
    <basicHttpBinding>
        <binding name="basicHttpLargeMessage" maxReceivedMessageSize="5242880" maxBufferSize="5242880">
            <readerQuotas maxArrayLength="5242880" />
        </binding>
    </basicHttpBinding>
</bindings>

I can now upload and download files up to 5MB through my service.

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit

Comments (5)

Thanks! I was stuck for hours trying to get image data in byte array form sent from a Silverlight client to a WCF service. I figured out it was a problem with the size of the data, but the standard discussions elsewhere didn’t fix it. Your tip did the trick.

Hi Byran

Glad it helped you out

Thank you! It was very useful, and helped me a lot.

I was stuck for hours, thanks.

Silverlight 4 Wcf Not Found

Thx A lot!!

was stuck too for quite some time – your trick helped me a lot :)

Write a comment