【问题标题】:Silverlight & WCF: Max message sizeSilverlight 和 WCF:最大消息大小
【发布时间】:2008-12-01 04:16:49
【问题描述】:

当我使用 WCF 从我的 silverlight 应用程序中传递一个对象列表时,一切正常,直到列表变得太大。似乎当我超过 80 个项目时出现错误: 远程服务器返回意外响应:(404) Not Found

我推测这是因为列表变得太大,因为当列表有 70 个项目时,一切正常。奇怪的错误信息,对吧?

在配置文件中,我将 maxBufferSize 更改为它将接受的最大值,但我的列表中仍然不能有超过 80 个项目。

如何在不拆分对象的情况下传递大对象?


谢谢肖恩,那我到底在哪里做呢? 这是我的 ServiceReferences.ClientConfig

<configuration>
<system.serviceModel>
    <client>
      <!--"http://sy01911.fw.gsjbw.com/WcfService1/Service1.svc"-->
      <endpoint address="http://localhost/WcfService1/Service1.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService11"
            contract="SilverlightApplication1.ServiceReference1.IService1"
            name="BasicHttpBinding_IService1" />
    </client>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_IService1" maxBufferSize="655360000"
                maxReceivedMessageSize="655360000">
                <security mode="None" />
            </binding>
            <binding name="BasicHttpBinding_IService11" maxBufferSize="655360000"
                maxReceivedMessageSize="655360000">
                <security mode="None" />
            </binding>
        </basicHttpBinding>
    </bindings>
</system.serviceModel>


这是你提到的服务器配置


<services>
  <service name="WcfService1.Service1" behaviorConfiguration="WcfService1.Service1Behavior" >
    <!-- Service Endpoints -->
    <endpoint address="" binding="basicHttpBinding" contract="WcfService1.IService1" >
      <!-- 
          Upon deployment, the following identity element should be removed or replaced to reflect the 
          identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
          automatically.
      -->
      <identity>
        <dns value="localhost"/>
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="WcfService1.Service1Behavior">
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
      <serviceMetadata httpGetEnabled="true"/>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

【问题讨论】:

    标签: c# .net wcf silverlight


    【解决方案1】:

    如果您从 WCF 发送大量项目,还要确保 maxItemsInObjectGraph 是一个相对较高的数字

    <behaviors>
       <serviceBehaviors>
          <behavior name="YourBahvior">
             <dataContractSerializer maxItemsInObjectGraph="6553600"/>
          </behavior>
       </serviceBehaviors>
    </behaviors>
    

    【讨论】:

      【解决方案2】:

      有两个配置文件。 silverlight clientconfig 将允许您发送更大的消息,但如果您使用 WCF,则有一个服务器 web.config 会限制接收到的消息的大小(以防止 DDOS 攻击)。

      【讨论】:

      • 嗨,肖恩,对我下面的评论有什么建议吗?
      【解决方案3】:

      在服务器端,修改配置文件,使服务可以接受大消息。

      1. &lt;system.serviceModel&gt; 部分添加basicHttpBinding 配置:

        <?xml version="1.0" encoding="utf-8" ?>
        <configuration>
            <system.serviceModel>
               <bindings>
                 <basicHttpBinding>
                    <binding name="MyBasicHttpBinding" maxReceivedMessageSize="300000000">
                       <security mode="None"/>
                       <readerQuotas maxStringContentLength="300000000"/>
                    </binding>
                 </basicHttpBinding>
               </bindings>
        .......
        
      2. 将配置添加到服务绑定。

        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="MyBasicHttpBinding" contract="WcfService1.IService1">
        

      【讨论】:

        猜你喜欢
        • 2010-09-27
        • 2010-12-15
        • 2017-05-05
        • 1970-01-01
        • 1970-01-01
        • 2010-11-14
        • 2015-04-02
        • 2020-10-06
        • 1970-01-01
        相关资源
        最近更新 更多