C# WCF 服务 maxReceivedMessageSize basicHttpBinding 问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11068612/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 16:21:35  来源:igfitidea点击:

WCF service maxReceivedMessageSize basicHttpBinding issue

c#wcfwcf-binding

提问by BlargleMonster

I can't seem to get my WCF service to accept large amounts of data being sent up to it.

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

I configured the maxReceivedMessageSize for the client and could receive large data down just fine, that's not the issue. It's sending data up to the service.

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

I tried to configure the service but haven't had any luck. Here's my web.config:

我尝试配置该服务,但没有任何运气。这是我的 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>

采纳答案by TRayburn

Removing the name from your binding will make it apply to all endpoints, and should produce the desired results. As so:

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

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

Also note that I removed the bindingConfigurationattribute from the endpoint node. Otherwise you would get an exception.

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

This same solution was found here : Problem with large requests in WCF

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

回答by carlosfigueira

Is the name of your service class really IService(on the Service namespace)? What you probably had originally was a mismatch in the name of the service class in the nameattribute of the <service>element.

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

回答by Serj Sagan

When using HTTPS instead of ON the binding, put it IN the binding with the httpsTransporttag:

当使用 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>