【问题标题】:I am Getting System.Threading.Tasks.Task.ThrowIfExceptional in wcf and Web Api REST Web Services for the large data我在 wcf 和 Web Api REST Web 服务中获取 System.Threading.Tasks.Task.ThrowIfExceptional 以获取大数据
【发布时间】:2014-12-17 12:36:12
【问题描述】:

我已经创建了 WCF 和 Web Api REST 完整的 Web 服务。在这个网络服务中,我得到了

用于大数据传输。

EX:在这种情况下,我有 25 列和 25000 行的 fetch 查询,有时数据来了,有时

这两个错误都会出现。 我的 WCF 配置。像这样

那么任何人都可以建议我。

【问题讨论】:

    标签: wcf c#-4.0 asp.net-web-api


    【解决方案1】:

    尝试在 web config reader quoata 中设置绑定 对于大传输,defualt 小

    详情:http://msdn.microsoft.com/en-us/library/ms731325(v=vs.110).aspx

    例子

    <binding name="myLargeBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
        <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" maxArrayLength="2147483647"/>
    </binding>
    

    然后不要忘记将此 bindningConfiguration 设置为端点

    <endpoint ....  binding="basicHttpBinding" bindingConfiguration="myLargeBinding" .... >
    

    对于您的 web.config,它应该是这样的。

    我创建了新的绑定配置“RESTBinding”并将其设置到您的端点。

      <?xml version="1.0"?>
    <configuration>
      <system.web>
        <compilation debug="true"  />
        <httpRuntime maxRequestLength ="1048576"/>
      </system.web>
      <system.serviceModel>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true"></serviceHostingEnvironment>
        <services>
          <service behaviorConfiguration="" name="wcfTestHC.TestHC">
            <endpoint address="" behaviorConfiguration="RestEndpointBehavior" binding="webHttpBinding" bindingConfiguration="RESTBinding" contract="wcfTestHC.ITestHC"  />
            <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
          </service>
        </services>
        <behaviors>
          <endpointBehaviors>
            <behavior name="RestEndpointBehavior">
              <webHttp  helpEnabled="true" />
              <dataContractSerializer maxItemsInObjectGraph="2147483647" />
            </behavior>
          </endpointBehaviors>
          <serviceBehaviors>
            <behavior name="Default">
              <serviceMetadata httpGetEnabled="true" />
              <serviceThrottling maxConcurrentCalls="250" maxConcurrentInstances="75" maxConcurrentSessions="50"/>
              <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
            </behavior>
            <behavior name="">
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="true" />
              <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <bindings>
          <webHttpBinding>
            <binding  name="RESTBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00"
                     sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
              maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"
              useDefaultWebProxy="true">
              <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"  maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" maxArrayLength="2147483647"/>        
            </binding>
          </webHttpBinding>
          <wsHttpBinding>
            <binding name="EndpointBehavior" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00"
                     sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
              maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8"
              useDefaultWebProxy="true">
              <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" maxArrayLength="2147483647"/>
              <reliableSession enabled="True" ordered ="True "/>
            </binding>
          </wsHttpBinding>
        </bindings>
        <diagnostics>
          <messageLogging logEntireMessage="true" logMalformedMessages="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" maxMessagesToLog="3000" />
        </diagnostics>     
      </system.serviceModel>
     <system.diagnostics>
        <switches>
          <add name="XmlSerialization.Compilation" value="4"/>
      </switches>
       <sources>
          <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
            <listeners>
              <add name="xml" />
            </listeners>
          </source>
          <source name="System.ServiceModel.MessageLogging">
            <listeners>
              <add name="xml" />
            </listeners>
          </source>
        </sources>
        <sharedListeners>
          <add name="xml" type="System.Diagnostics.XmlWriterTraceListener" initializeData="c:\temp\WCFLoging.svclog" />
        </sharedListeners>
      </system.diagnostics>
      <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
        <directoryBrowse enabled="true"/>
        <security>
          <requestFiltering>
            <requestLimits maxAllowedContentLength ="1073741824"></requestLimits>
          </requestFiltering>
        </security>
      </system.webServer>
    </configuration>
    

    如果您仍然遇到错误。也许问题出在其他地方。 尝试将这些设置插入您的 web.config。这将为您的服务提供详细的日志记录和异常详细信息,我们将在那里查看问题所在。我已将日志的位置设置为 c:\temp\WCFLoging.svclog,如果需要,请更改它,并且我已经使用这些设置编辑了 web.config 的示例 - 准备好复制和粘贴 :-)

    <system.serviceModel>
        <diagnostics>
          <messageLogging logEntireMessage="true" logMalformedMessages="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" maxMessagesToLog="3000" />
        </diagnostics>     
      </system.serviceModel>
    

    <system.diagnostics>
        <switches>
          <add name="XmlSerialization.Compilation" value="4"/>
      </switches>
       <sources>
          <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
            <listeners>
              <add name="xml" />
            </listeners>
          </source>
          <source name="System.ServiceModel.MessageLogging">
            <listeners>
              <add name="xml" />
            </listeners>
          </source>
        </sources>
        <sharedListeners>
          <add name="xml" type="System.Diagnostics.XmlWriterTraceListener" initializeData="c:\temp\WCFLoging.svclog" />
        </sharedListeners>
      </system.diagnostics>
    

    【讨论】:

    • Polacekpavwl,感谢您的回复。实际上我在绑定标签上没有得到像maxBufferSize="2147483647" transferMode="Buffered" 这样的选项。我正在使用 4.5 框架。你能建议我吗?
    • 在您的端点部分 缺少 bindingConfiguration 元素,因此端点不知道您要设置什么配置,因此一切都是默认的。另一个问题是您的端点具有 binding="webHttpBinding"(这对休息有好处)但配置绑定元素是 。如果您将配置作为文本而不是图像传递,我会为您更正
    • 嗨 Polacekpavwl,感谢您的回复。只需检查此链接,您将获得代码 (codeproject.com/Questions/854390/…)。建议我在同一个..
    • 嗨 Polacekpavwl,我听从了您的建议,但我仍然收到与我在帖子中提到的相同的错误...我在配置上做错了什么。或者我错过了我的配置中的任何内容。文件...请在这方面给我建议...
    • 请看我编辑的答案。我已经用诊断设置更新了它。请更改它并再次调用它。
    猜你喜欢
    • 1970-01-01
    • 2016-08-30
    • 1970-01-01
    • 2017-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-22
    相关资源
    最近更新 更多