views:

961

answers:

6

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"/&gt;
    </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?

+1  A: 

If the service is being hosted in ASP.NET, you'll also want to make sure that the max request length for the web server allows for messages of that size. For example:

<configuration>
  <system.web>
    <httpRuntime maxRequestLength="2147483647" />
  </system.web>
</configuration>
Jacob
I added your tag to my web.config file. I got an error because that's too big for that field, so I set it down to it's max: maxRequestLength="2097151". But I'm still getting the error.FYI, I'm downloading pictures so I know that the size of the picture might be larger than 64Kb, but it's not greater than 2GB. And those pictures that are smaller than 64Kb are working just fine.
Steve Brownell
A: 

You haven't shown us your < services > element. Do you have something along the lines of

<services>
    <service behaviorConfiguration="GiveWeb.Services.ShopBehavior" name="blah">
        ...
    </service>
</services>

?

serialhobbyist
A: 

Everything looks fine to me, so I wonder if this is something simple. Is the server where you're changing the configuration the same one that the Silverlight client is pointing to at https://web14.ai-host.com/Services/Shop.svc? Also, you may want to try pasting the exact same binding configuration from the server config to the client's binding configuration.

Jacob
the server is the same.I've tried copying the binding settings to the silverlight client file, but the tags are not all allowed (as I mention above in other comments).
Steve Brownell
A: 

OK, here's another try. Some versions of Silverlight 2 weren't reading the ClientConfig properly, so it was worked around by setting MaxReceivedMessageSize on the client binding through code. Maybe Silverlight 3 has a similar issue. Could you try setting MaxReceivedMessageSize through code? See http://forums.silverlight.net/forums/t/11313.aspx.

Jacob
I tried to set these, but they are not available properties of the basicHttpBinding object in the silverlight client.
Steve Brownell
Sure they are. When I say set through code, I don't mean the XML in the config file. The API reference for MaxReceivedMessageSize is here: http://msdn.microsoft.com/en-us/library/system.servicemodel.basichttpbinding.maxreceivedmessagesize(VS.95).aspx
Jacob
My client is setup with the following code to make a method call:lxAddress = new System.ServiceModel.EndpointAddress(new Uri(Application.Current.Host.Source, "../Services/Shop.svc"));lxBinding = new System.ServiceModel.BasicHttpBinding(System.ServiceModel.BasicHttpSecurityMode.Transport);lxProxy = new GiveSL.ShopSVC.ShopClient(lxBinding, lxAddress);the lxBinding object does not have a "MaxReceivedMessageSize" property. I'm using the Web Express version of VS. I hope that's not the issue.
Steve Brownell
Odd that you're not seeing the clearly-documented properties. Are you sure you're not using Silverlight 2 rather than Silverlight 3 like your question is tagged?
Jacob
A: 

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);
 }
Steve Brownell
A: 

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

Steve Brownell