【问题标题】:WCF service maxReceivedMessageSize basicHttpBinding issueWCF 服务 maxReceivedMessageSize basicHttpBinding 问题
【发布时间】:2012-06-19 13:58:49
【问题描述】:

我似乎无法让我的 WCF 服务接受发送给它的大量数据。

我为客户端配置了 maxReceivedMessageSize 并且可以很好地接收大数据,这不是问题。它正在向服务发送数据。

我尝试配置服务,但没有任何运气。这是我的 web.config:

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true"/>
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false" />
          <serviceDiscovery />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service name="Service.IService">
        <clear />
        <endpoint binding="basicHttpBinding" bindingConfiguration="MessageSizeBasic" contract="Service.IService" />
      </service>
    </services>
    <bindings>
      <basicHttpBinding>
        <binding name="MessageSizeBasic" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="32" maxStringContentLength="2147483647"
            maxArrayLength="16348" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
        </binding>
      </basicHttpBinding>
      <webHttpBinding>
        <binding name="MessageSizeWeb" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" />
      </webHttpBinding>
    </bindings>
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

【问题讨论】:

    标签: c# wcf wcf-binding


    【解决方案1】:

    从绑定中删除名称将使其适用于所有端点,并应产生所需的结果。因此:

    <services>
      <service name="Service.IService">
        <clear />
        <endpoint binding="basicHttpBinding" contract="Service.IService" />
      </service>
    </services>
    <bindings>
      <basicHttpBinding>
        <binding maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="32" maxStringContentLength="2147483647"
            maxArrayLength="16348" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
        </binding>
      </basicHttpBinding>
      <webHttpBinding>
        <binding maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" />
      </webHttpBinding>
    </bindings>
    

    另请注意,我从端点节点中删除了 bindingConfiguration 属性。否则你会得到一个异常。

    在这里找到了同样的解决方案:Problem with large requests in WCF

    【讨论】:

    • 非常感谢。作为说明,我还必须从端点中删除 bindingConfiguration 属性,因为它引用了我取出的名称。
    • 除了以上web.config的改动,我还需要做什么?
    • 请参考这篇文章来检查我的 web.config 文件。 [stackoverflow.com/questions/22525783/…
    • 我一直为此头疼...谢谢,这让我度过了一个美好的早晨。
    【解决方案2】:

    当使用 HTTPS 而不是 ON 绑定时,将其放在带有httpsTransport 标签的绑定中:

        <binding name="MyServiceBinding">
          <security defaultAlgorithmSuite="Basic256Rsa15" 
                    authenticationMode="MutualCertificate" requireDerivedKeys="true" 
                    securityHeaderLayout="Lax" includeTimestamp="true" 
                    messageProtectionOrder="SignBeforeEncrypt" 
                    messageSecurityVersion="WSSecurity10WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10"
                    requireSignatureConfirmation="false">
            <localClientSettings detectReplays="true" />
            <localServiceSettings detectReplays="true" />
            <secureConversationBootstrap keyEntropyMode="CombinedEntropy" />
          </security>
          <textMessageEncoding messageVersion="Soap11WSAddressing10">
            <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" 
                          maxArrayLength="2147483647" maxBytesPerRead="4096" 
                          maxNameTableCharCount="16384"/>
          </textMessageEncoding>
          <httpsTransport maxReceivedMessageSize="2147483647" 
                          maxBufferSize="2147483647" maxBufferPoolSize="2147483647" 
                          requireClientCertificate="false" />
        </binding>
    

    【讨论】:

      【解决方案3】:

      您的服务类的名称真的是 IService(在 Service 命名空间上)吗?您最初可能遇到的是 &lt;service&gt; 元素的 name 属性中的服务类名称不匹配。

      【讨论】:

      • 我现在的服务接口确实是IService。我以后可能会更改它,但现在它在我的系统中有点单例。
      • 服务interface,还是服务class&lt;service&gt; 元素的 name 属性的值必须是服务的名称。
      • 我尝试了这些选项,这是另一种可能的解决方案。我不确定为什么服务配置编辑器工具只让我在管理服务时选择接口,但如果我需要再次使用名称,我很高兴知道另一种修复方法。
      • 我正在使用 WCF rest online 40 模板。服务名称应该是什么?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-10
      • 1970-01-01
      • 1970-01-01
      • 2012-01-10
      • 1970-01-01
      • 1970-01-01
      • 2011-03-09
      相关资源
      最近更新 更多