wcfsilverlight-3.0maxreceivedmessagesize

silverlight 3 wcf service configuration -- getting maxreceivedmessagesize error


I'm getting the maxreceivedmessagesize error for messages greater than 64K. The problem is that I've already changed everything in both server and client, and it's not fixing the problem.

here's my web.config on the server and then the silverlight client config:

<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding name="secureobjectbind" maxBufferSize="2147483647"
          maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647">
        <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
          maxArrayLength="2147483647" maxBytesPerRead="2147483647"
          maxNameTableCharCount="2147483647" />
        <security mode="Transport" />
      </binding>
    </basicHttpBinding>
  </bindings>
  <behaviors>
    <serviceBehaviors>
      <behavior name="GiveWeb.Services.ShopBehavior">
        <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" />
        <serviceDebug includeExceptionDetailInFaults="true" />
        <dataContractSerializer maxItemsInObjectGraph="6553600" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <services>
    <service behaviorConfiguration="GiveWeb.Services.ShopBehavior"
        name="GiveWeb.Services.Shop">
      <endpoint address="" binding="basicHttpBinding" 
          bindingConfiguration="secureobjectbind" 
          contract="GiveWeb.Services.IShop">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
      <endpoint address="mex" binding="mexHttpsBinding" 
        contract="IMetadataExchange" />
    </service>
  </services>
  <serviceHostingEnvironment>
    <baseAddressPrefixFilters>
      <clear/>
      <add prefix="http://www.ushop2give.com"/>
    </baseAddressPrefixFilters>
  </serviceHostingEnvironment>
</system.serviceModel>

silverlight client

<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IShop" maxBufferSize="2147483647"
                    maxReceivedMessageSize="2147483647">
                    <security mode="Transport" />
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="https://web14.ai-host.com/Services/Shop.svc"
                binding="basicHttpBinding" 
                bindingConfiguration="BasicHttpBinding_IShop"
                contract="ShopSVC.IShop" name="BasicHttpBinding_IShop" />
        </client>
    </system.serviceModel>
</configuration>

so why am I still getting the error?


Ok, here's somemore info for the post...

I found one error. My original declaration for my binding object was as System.ServiceModel.Channels.Binding not System.ServiceModel.BasicHttpBinding. That's why I wasn't seeing the properties for MaxReceivedMessageSize on the object.

I have corrected this and created a function to create my proxy, But I'm still getting an error message when more than 65536 bytes are in the return message.

     public static ShopSVC.ShopClient ShopClientProxy()
 {
     System.ServiceModel.EndpointAddress lxAddress = new System.ServiceModel.EndpointAddress(new Uri(Application.Current.Host.Source, "../Services/Shop.svc"));

     System.ServiceModel.BasicHttpBinding lxBinding = new System.ServiceModel.BasicHttpBinding(System.ServiceModel.BasicHttpSecurityMode.Transport);
     lxBinding.MaxReceivedMessageSize = 2147483647;
     lxBinding.MaxBufferSize = 2147483647;
     lxBinding.ReceiveTimeout = new TimeSpan(0, 5, 0);

     return new GiveSL.ShopSVC.ShopClient(lxBinding, lxAddress);
 }

Solution

  • Finally a solution...

    There were two underlying problems:

    1. The binding object on the client side was incorrectly declared as System.ServiceModel.Channels.Binding and should have been declared as System.ServiceModel.BasicHttpBinding. So, the function listed above is the correct code for creating the proxy object in the Silverlight client.
    2. It must be that the very first call to the service client is cached by the application. All this time I've been trying to work a solution, I was only changing one of the binding calls, and it wasn't the first one called in my project. When I wrote the central function for creating the proxy object it still didn't work until I changed all my code everywhere to use that central function.

    Now that all my code uses the same function for creating the service client proxy, the setting of MaxReceivedMessageSize is respected and all is well.

    Wow... just never saw that one coming.

    Thanks everyone (especially Jacob) for hanging with me on this one.

    Steve