为什么我的WCF Web服务在输出数据相当大时结束响应?

Nic*_*s H 4 asp.net wcf

我已经设置了一个WCF Web服务,可以从我的网站上调用.它工作得很好,但是如果我请求大量数据(不确定大小,但它比我正在返回的"标准"数据容易3-4倍),Cassini(Visual Studio Web Server)就会关闭没有发送任何东西的反应 - 没有错误或任何 事件日志中没有任何内容.只是虚无...

我是WCF的新手,但我知道必须有一些我在这里缺少的配置选项(如消息/响应最大大小/限制)来解决我的问题.这是我的web.config部分的样子:

<system.serviceModel>   
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />   
   <behaviors>
   <endpointBehaviors>
    <behavior name="securetmhAspNetAjaxBehavior">
     <enableWebScript />
    </behavior>
   </endpointBehaviors>
   <serviceBehaviors>
    <behavior name="tmhsecureBehavior">
     <serviceMetadata httpGetEnabled="false" />
     <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
   </serviceBehaviors>
  </behaviors>
  <services>
   <service name="securetmh">
    <endpoint address="" behaviorConfiguration="securetmhAspNetAjaxBehavior" binding="webHttpBinding" contract="securetmh" />
   </service>
  </services>
 </system.serviceModel>
Run Code Online (Sandbox Code Playgroud)

任何帮助,将不胜感激.

mar*_*c_s 5

出于安全原因,WCF默认将服务调用返回的数据限制为64 K.

你可以明显地改变这一点 - 有大量的条目可以调整.请在此处查看此示例配置:

  <system.serviceModel>
    <bindings>
      <webHttpBinding>
        <binding name="customWebHttp"
                 maxBufferPoolSize="256000"
                 maxReceivedMessageSize="256000"
                 maxBufferSize="256000">
          <readerQuotas 
            maxArrayLength="256000"
            maxStringContentLength="256000"/>
        </binding>
      </webHttpBinding>
    </bindings>
    <services>
      <service name="YourService">
        <endpoint name="test"
                  address="....."
                  binding="webHttpBinding"
                  bindingConfiguration="customWebHttp"
                  contract="IYourService" />
      </service>
    </services>
  </system.serviceModel>
Run Code Online (Sandbox Code Playgroud)

您需要定义一个自定义绑定配置基础上webHttpBinding,你可以调整所有这些不同的设置-我把它们全部设置为256K(而不是64K).

希望这可以帮助!

  • 谢谢,这让我大部分都在那里.为了记录,我还必须增加服务绑定的maxItemsInObjectGraph属性:<dataContractSerializer maxItemsInObjectGraph ="6553600"/> (2认同)