silverlight 3 wcf service configuration -- getting maxreceivedmessagesize error
Asked Answered
I

4

1

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);
 }
Illyes answered 29/1, 2010 at 18:8 Comment(4)
Could you post the exact error message you're receiving?Is
System.ServiceModel.CommunicationException: The Maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize Property on the appropriate binding element.Illyes
Maybe your service isn't using the behavior you defined. Could you add the service definition and endpoints to the post?Is
Maybe configuring tracing on your service can yield some clues. msdn.microsoft.com/en-us/library/ms733025.aspx tells how.Is
I
0

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

Illyes answered 12/2, 2010 at 17:57 Comment(0)
I
1

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>
Is answered 29/1, 2010 at 18:21 Comment(1)
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.Illyes
I
0

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.

Is answered 30/1, 2010 at 18:9 Comment(1)
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).Illyes
I
0

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.

Is answered 30/1, 2010 at 20:57 Comment(4)
I tried to set these, but they are not available properties of the basicHttpBinding object in the silverlight client.Illyes
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: msdn.microsoft.com/en-us/library/…Is
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.Illyes
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?Is
I
0

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

Illyes answered 12/2, 2010 at 17:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.