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

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.

Posted on by Joe in Silverlight

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

  1. Bryan B

    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.

  2. Joe

    Hi Byran

    Glad it helped you out

  3. elGekko

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

  4. Torak

    I was stuck for hours, thanks.

    Silverlight 4 Wcf Not Found

  5. weissbrot

    Thx A lot!!

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

  6. Gio

    Thanks for this. I have a slightly different situation though. My binding is Custom and it doesn’t look like it has properties mentioned in the post. Has anyone tried this with custom binding?

  7. Arasu

    very very
    Thanks

  8. Kamlesh

    Hey, Thx A lot!!

Add a Comment