【问题标题】:silverlight 3 wcf service configuration -- getting maxreceivedmessagesize errorsilverlight 3 wcf 服务配置——出现 maxreceivedmessagesize 错误
【发布时间】:2010-01-29 18:08:14
【问题描述】:

我收到大于 64K 的消息的 maxreceivedmessagesize 错误。问题是我已经更改了服务器和客户端中的所有内容,但并没有解决问题。

这是我在服务器上的 web.config,然后是 silverlight 客户端配置:

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

银光客户端

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

那么为什么我仍然收到错误消息?


好的,这是帖子的更多信息...

我发现了一个错误。我对绑定对象的原始声明是 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);
 }

【问题讨论】:

  • 您能否发布您收到的确切错误消息?
  • System.ServiceModel.CommunicationException:已超出传入消息的最大消息大小配额 (65536)。要增加配额,请在适当的绑定元素上使用 MaxReceivedMessageSize 属性。
  • 也许您的服务没有使用您定义的行为。您能否将服务定义和端点添加到帖子中?
  • 也许在您的服务上配置跟踪可以产生一些线索。 msdn.microsoft.com/en-us/library/ms733025.aspx 告诉我们怎么做。

标签: wcf silverlight-3.0 maxreceivedmessagesize


【解决方案1】:

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

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

【讨论】:

  • 我已将您的标签添加到我的 web.config 文件中。我收到一个错误,因为该字段太大,所以我将其设置为最大值:maxRequestLength="2097151"。但我仍然收到错误消息。仅供参考,我正在下载图片,所以我知道图片的大小可能大于 64Kb,但不大于 2GB。而那些小于 64Kb 的图片也可以正常工作。
【解决方案2】:

在我看来一切都很好,所以我想知道这是否简单。您更改配置的服务器是否与 Silverlight 客户端指向 https://web14.ai-host.com/Services/Shop.svc 的服务器相同?此外,您可能想尝试将完全相同的绑定配置从服务器配置粘贴到客户端的绑定配置。

【讨论】:

  • 服务器是一样的。我尝试将绑定设置复制到 silverlight 客户端文件,但标签并非全部允许(正如我在上面在其他 cmets 中提到的那样)。
【解决方案3】:

好的,这是另一个尝试。 Silverlight 2 的某些版本没有正确读取 ClientConfig,因此通过代码在客户端绑定上设置 MaxReceivedMessageSize 来解决它。也许 Silverlight 3 也有类似的问题。您可以尝试通过代码设置 MaxReceivedMessageSize 吗?见http://forums.silverlight.net/forums/t/11313.aspx

【讨论】:

  • 我尝试设置这些,但它们不是 silverlight 客户端中 basicHttpBinding 对象的可用属性。
  • 当然是。当我说通过代码设置时,我并不是指配置文件中的 XML。 MaxReceivedMessageSize 的 API 参考在这里:msdn.microsoft.com/en-us/library/…
  • 我的客户端设置了以下代码以进行方法调用: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); lxBinding 对象没有“MaxReceivedMessageSize”属性。我正在使用 VS 的 Web Express 版本。我希望这不是问题。
  • 奇怪的是,您没有看到明确记录的属性。你确定你没有使用 Silverlight 2 而不是 Silverlight 3,就像你的问题被标记一样?
【解决方案4】:

终于有办法了……

有两个潜在的问题:

  1. 客户端的绑定对象被错误地声明为 System.ServiceModel.Channels.Binding,应该被声明为 System.ServiceModel.BasicHttpBinding。因此,上面列出的函数是在 Silverlight 客户端中创建代理对象的正确代码。
  2. 必须是应用程序缓存了对服务客户端的第一次调用。一直以来,我一直在尝试解决方案,我只更改了一个绑定调用,而且它不是我项目中的第一个调用。当我编写用于创建代理对象的中心函数时,它仍然无法正常工作,直到我更改所有代码以使用该中心函数。

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

哇...只是没看到那个来了。

感谢大家(尤其是 Jacob)与我一起讨论这个问题。

史蒂夫

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-22
    • 2011-11-13
    • 1970-01-01
    • 1970-01-01
    • 2011-07-26
    • 1970-01-01
    • 2012-06-19
    • 2011-03-28
    相关资源
    最近更新 更多