【问题标题】:Still unable to transfer large amounts of data via WCF - what else is wrong?仍然无法通过 WCF 传输大量数据 - 还有什么问题?
【发布时间】:2012-01-22 03:20:08
【问题描述】:

我遇到了一个问题,我试图从我的 WCF 服务传输大量对象。我必须将对象的传输限制为 100,否则会出现某种通信错误。

我尝试了解决方案中的建议,找到了here,但可能我遗漏了一些东西,因为我仍然收到错误消息。

这是我的 WCF 服务的 web.config 的底部:

 <system.web>
    <httpRuntime maxRequestLength="102400" />
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="MyWsHttpBinding" />
      </wsHttpBinding>
      <netTcpBinding>
        <binding name="myNetTcpBinding"
                 closeTimeout="00:01:00"
                 openTimeout="00:01:00"
                 receiveTimeout="00:10:00"
                 sendTimeout="00:01:00"
                 transactionFlow="false"
                 transferMode="Buffered"
                 transactionProtocol="OleTransactions"
                 hostNameComparisonMode="StrongWildcard"
                 listenBacklog="10"
                 maxBufferPoolSize="2147483647"
                 maxBufferSize="524288"
                 maxConnections="10"
                 maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="32"
                        maxStringContentLength="8192"
                        maxArrayLength="16384"
                        maxBytesPerRead="4096"
                        maxNameTableCharCount="16384" />
          <reliableSession ordered="true"
                           inactivityTimeout="00:10:00"
                           enabled="false" />
          <security mode="Transport">
            <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
          </security>
        </binding>
      </netTcpBinding>
    </bindings>

    <behaviors>
      <serviceBehaviors>
        <behavior name="myNetTcpBehaviour">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>        
        <behavior>
          <!-- 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>
      <endpointBehaviors>
        <behavior name="myNetTcpEndPointBehaviour">
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

接下来,这里是使用 Web 服务的网站的 web.config 部分的下部:

  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IFeederService" 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="524288" maxReceivedMessageSize="2147483647"
          messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
          useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="55000" maxArrayLength="16384"
            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"
              realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>

    <behaviors>
      <endpointBehaviors>
        <behavior name="myEndPointBehavior">
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
        </behavior>
      </endpointBehaviors>
    </behaviors>

    <client>

      <endpoint address="http://www.mysiate.com/MyService.svc"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IFeederService"
        contract="FeederService.IFeederService" name="BasicHttpBinding_IFeederService" />
    </client>   </system.serviceModel>

我得到的错误是:

接收到的 HTTP 响应时出错 http://www.mysite.com/MyService.svc。这可能是由于服务 端点绑定不使用 HTTP 协议。这也可能是由于 到被服务器中止的 HTTP 请求上下文(可能是由于 到服务关闭)。有关详细信息,请参阅服务器日志。

奇怪的是,在我写这篇文章的时候,我重试了它,将返回逻辑更改为 190 个对象,它成功了。重试,失败。

这可能是更改某些 IIS 设置的问题吗?

我们将不胜感激。

谢谢。

【问题讨论】:

  • this 怎么样?
  • 这也可能有助于stackoverflow.com/questions/1281269/…。问题可能是由于 basichttpbinding 配置的大小限制。
  • 你一共转账多少钱?
  • 开启跟踪 - 这应该可以查明您的请求失败的原因

标签: c# wcf service large-data-volumes


【解决方案1】:

错误信息说:

...有关详细信息,请参阅服务器日志。

我将首先按照this MSDN article 中的说明在服务器上配置跟踪。

【讨论】:

    【解决方案2】:

    您尚未在服务配置中声明任何端点,这意味着正在使用 WCF 默认端点模型

    但是,您已经命名了绑定配置和行为,这意味着它们不会被默认端点拾取。如果您从绑定配置和行为中删除名称,那么它们将成为默认设置并被默认端点拾取

    【讨论】:

      【解决方案3】:

      您不能使用“流式”WCF 绑定吗?

      WCF & Streaming

      【讨论】:

        【解决方案4】:

        您的绑定需要将行为配置设置为您的行为。

          <endpoint address="http://www.mysiate.com/MyService.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IFeederService"
            behaviorConfiguration="myEndPointBehavior" contract="FeederService.IFeederService" name="BasicHttpBinding_IFeederService" />
        </client>   </system.serviceModel>
        

        否则将不会使用图形设置

        【讨论】:

          猜你喜欢
          • 2012-04-29
          • 2011-09-22
          • 1970-01-01
          • 2012-02-24
          • 2018-03-06
          • 2018-05-04
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多