Silverlight& WCF:最大邮件大小

时间:2008-12-01 04:16:49

标签: c# .net wcf silverlight

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

我认为这是因为List已经变得太大了,就像List有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>

3 个答案:

答案 0 :(得分:3)

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

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

答案 1 :(得分:2)

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

答案 2 :(得分:2)

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

  1. basicHttpBinding部分添加<system.serviceModel>配置:

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