-->

Silverlight 3的WCF服务配置 - 让maxreceivedmessagesize错误(

2019-10-19 07:22发布

我得到的大于64k消息maxreceivedmessagesize错误。 问题是,我已经在服务器和客户机改变了一切,它不是解决问题。

这里是我的服务器,然后Silverlight客户端配置上的web.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客户端

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

所以为什么我仍然得到错误?


好吧,这里是为后somemore信息...

我发现了一个错误。 我原来的声明我结合目标物的System.ServiceModel.Channels.Binding不System.ServiceModel.BasicHttpBinding。 这就是为什么我没有看到物体上MaxReceivedMessageSize的属性。

我已经纠正了这一点,并创建了一个函数来创建我的代理,但是当超过65536个字节在返回消息我仍然收到错误消息。

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

Answer 1:

如果该服务在ASP.NET主持过程中,你还需要确保Web服务器的最大请求长度允许该大小的消息。 例如:

<configuration>
  <system.web>
    <httpRuntime maxRequestLength="2147483647" />
  </system.web>
</configuration>


Answer 2:

一切看起来没什么问题,所以我不知道这是否是简单的东西。 在这里您要更改配置的Silverlight客户端在指向同一个服务器https://web14.ai-host.com/Services/Shop.svc ? 此外,您还可以尝试从服务器配置到客户端的绑定配置粘贴完全相同的绑定配置。



Answer 3:

OK,这里是另一种尝试。 Silverlight 2中的某些版本不读ClientConfig正确,所以它是由客户端通过代码绑定上设置MaxReceivedMessageSize各地工作。 也许Silverlight 3中也有类似的问题。 你可以尝试通过代码设置MaxReceivedMessageSize? 见http://forums.silverlight.net/forums/t/11313.aspx 。



Answer 4:

最后的解决方案......

有两个基本问题:

  1. 在客户端的绑定对象被错误地宣布为System.ServiceModel.Channels.Binding,应该已被宣布为System.ServiceModel.BasicHttpBinding。 因此,上面列出的功能是建立在Silverlight客户端代理对象正确的代码。
  2. 它必须是在服务客户端的第一个电话是由应用程序缓存。 这段时间我一直在努力工作的解决方案,我只是改变了绑定呼叫中的一个,这是不叫我的项目中的第一个。 当我写了核心功能,用于创建代理对象它仍然没有工作,直到我改变了我的所有代码到处使用该中心的功能。

现在,我的所有代码使用相同功能创建服务客户端代理,MaxReceivedMessageSize的设置是尊重,一切都很好。

哇...从来没有看见有人来。

谢谢大家(尤其是雅各布),与我挂这一个。

史蒂夫



文章来源: silverlight 3 wcf service configuration — getting maxreceivedmessagesize error