silverlight 3 wcf service configuration — getting maxreceivedmessagesize error

此生再无相见时 提交于 2019-12-11 10:04:26

问题


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);
 }

回答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>



回答2:


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.




回答3:


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.




回答4:


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



来源:https://stackoverflow.com/questions/2164065/silverlight-3-wcf-service-configuration-getting-maxreceivedmessagesize-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!