none
WCF service called from Silverlight 2: Works perfectly, unless submitted data size exceeds certain value

    Question

  • I have a WCF service that I'm calling from Silverlight.  Basically, the Silverlight client submits an Entity Framework object containing a text field to the backend service for storing in SQL Server.  Anyway, it works great...unless the text submitted is longer than a certain value.  Not sure what the failure threshold is exactly, nothing "ridiculous" though....10-20 thousand characters.  I set a breakpoint in the backend service (running on local system) but it never makes it that far.  Something is failing in the communication layer.

    The message I get is "CommunicationException was unhandled by usercode".   In Visual Web Developer, the exception appears to be related to generated code in Reference.cs.

    Not sure how to debug this.  As I said, the service works fine otherwise.

    Any suggestions?

    Thank you.

    Saturday, April 18, 2009 2:19 PM

Answers

  • Ken,

    OK.  A change to web.config fixed the problem.  (Thanks to the article/rant by michael at http://mjeaton.net/blog/archive/2008/05/12/wrestling-with-wcf.aspx).

    Added following under <basicHttpBinding>:

            <binding name="customBasicHttpBinding" closeTimeout="00:10:00" openTimeout="00:10:00"
                receiveTimeout="00:10:00" sendTimeout="00:10:00" bypassProxyOnLocal="false"
                hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647"
                maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647"
                messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                useDefaultWebProxy="true">
                <readerQuotas maxDepth="32"
                  maxStringContentLength="2147483647"
                  maxArrayLength="2147483647"
                  maxBytesPerRead="4096"
                  maxNameTableCharCount="4096" />
            </binding>       

    and then referenced that binding in

    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="customBasicHttpBinding" contract="Editor.Web.Services.MyCustomServices" />

    Those settings are probably overkill but this is a start (things work!).  Now I can go back and adjust to more reasonable values.  readerQuotas is probably the relevant element.

    The article you reference might also be a solution.  I hadn't seen that wcf config tool before.  Looks handy.

    Many Thanks for the pointers!!!

     

    Sunday, April 19, 2009 9:57 AM

All replies

  •  In the servicereferences.clientconfig file in the silverlight project the max size of data being is being set

     

    <configuration>
        <system.serviceModel>
            <bindings>
                <basicHttpBinding>
                    <binding name="BasicHttpBinding_Service1" maxBufferSize="65536"
                        maxReceivedMessageSize="65536">
                        <security mode="None" />
                    </binding>
                </basicHttpBinding>
            </bindings>
            <client>

     

     

    Saturday, April 18, 2009 2:55 PM
  •  Hi, Ken.  Thank you for the response.

     My servicereferences.clientconfig (which I assume this was generated at some point) contains even larger values for maxBufferSize and maxMessageReceivedSize:

    <system.serviceModel>
            <bindings>
                <basicHttpBinding>
                    <binding name="BasicHttpBinding_UserServices" maxBufferSize="2147483647"
                        maxReceivedMessageSize="2147483647">
                        <security mode="None" />
                    </binding>
                    <binding name="BasicHttpBinding_BookServices" maxBufferSize="2147483647"
                        maxReceivedMessageSize="2147483647">
                        <security mode="None" />
                    </binding>
                </basicHttpBinding>
            </bindings>
            <client>
                <endpoint address="http://localhost:1900/Services/Auth_Services/UserServices.svc"
                    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_UserServices"
                    contract="UserServicesReference.UserServices" name="BasicHttpBinding_UserServices" />
                <endpoint address="http://localhost:1900/Services/Book_Services/BookServices.svc"
                    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_BookServices"
                    contract="BookServices.BookServices" name="BasicHttpBinding_BookServices" />
            </client>
        </system.serviceModel>

     

    Anyway, still not working.  I enabled Nikhi's Web Development Helper (not sure I really know how to use it properly) and invoked the service.  When the service succeeds, the Status given is 200.  When it fails (with large amounts of text) the Status is 500.  Not sure what that means.  Time to google around.

     

    Saturday, April 18, 2009 4:32 PM
  •    A 500 error means there was an error returning the data from the service.  I would try truncating the data returned and see if that gets rid of the error

    Saturday, April 18, 2009 9:01 PM
  •    A 500 error means there was an error returning the data from the service.  I would try truncating the data returned and see if that gets rid of the error

     

    Well, it never actually makes it into the service routine on the server.  In the failing scenario, the breakpoint is never reached.

    I did manage to glean some more information from Web Development Helper.  I spotted the "Details" button off to the right for the failing service invocation.  Under "response" it has

    Normal 0 'There was an error deserializing the object of type <domain object type>. The maximum string content length quota (8192) has been exceeded while reading XML data. This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader. 

    So the <domain object type> in the message about it the entity that contains the long string.  My interpretation is that the server side wcf plumbing has an issue with size of the contained string I submitted.  Now I have to figure out where and how to adjust the mentioned parameters.  I'm assuming it'll be somewhere in web.config or ServiceReferences.ClientConfig (although I normally don't touch the latter).

    Sunday, April 19, 2009 8:58 AM
  • Ken,

    OK.  A change to web.config fixed the problem.  (Thanks to the article/rant by michael at http://mjeaton.net/blog/archive/2008/05/12/wrestling-with-wcf.aspx).

    Added following under <basicHttpBinding>:

            <binding name="customBasicHttpBinding" closeTimeout="00:10:00" openTimeout="00:10:00"
                receiveTimeout="00:10:00" sendTimeout="00:10:00" bypassProxyOnLocal="false"
                hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647"
                maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647"
                messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                useDefaultWebProxy="true">
                <readerQuotas maxDepth="32"
                  maxStringContentLength="2147483647"
                  maxArrayLength="2147483647"
                  maxBytesPerRead="4096"
                  maxNameTableCharCount="4096" />
            </binding>       

    and then referenced that binding in

    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="customBasicHttpBinding" contract="Editor.Web.Services.MyCustomServices" />

    Those settings are probably overkill but this is a start (things work!).  Now I can go back and adjust to more reasonable values.  readerQuotas is probably the relevant element.

    The article you reference might also be a solution.  I hadn't seen that wcf config tool before.  Looks handy.

    Many Thanks for the pointers!!!

     

    Sunday, April 19, 2009 9:57 AM
  • I wasted some days to avoid Not Found with passing complex data accross LAN. I was very suprise why can't pass List through WCF and even stream. But since I've seen your code I am very happy - you saved my time.

    Appreciate

    Monday, April 27, 2009 9:03 AM