WCF(413)请求实体太大

时间:2019-10-07 17:11:04

标签: c# .net wcf

仅在上载将近250k的byte []但在相同的配置下才能下载相同的byte []数组时才出错。

我已经研究了Streaming,但是单个参数不起作用,并且这些文件大小很大。我已经能够上传一个630字节的简单文本文件,并且效果很好。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
    <bindings>
        <basicHttpBinding>
          <binding name="BasicHttpBinding_IGenerateLetterWcf"
                   maxBufferSize="20000000" maxReceivedMessageSize="20000000"
                   closeTimeout="00:20:00" openTimeout="00:20:00" receiveTimeout="00:20:00" sendTimeout="00:20:00" >
            <readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          </binding>
        </basicHttpBinding>
    </bindings>
    <client>         
        <endpoint address="http://localhost:61394/GenerateLetterWcf.svc" 
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IGenerateLetterWcf" 
            contract="GenerateLetterWcfSvc.IGenerateLetterWcf" name="BasicHttpBinding_IGenerateLetterWcf" />          
    </client>
</system.serviceModel>
</configuration>
    <?xml version="1.0"?>
<configuration>
  <connectionStrings>
    <add name="DTPLibrary.Properties.Settings.XXXXConnectionString1" connectionString="data source=XXXXX;initial catalog=XXXXXX;User ID=SQLAdmin;Password=XXXXXX" providerName="System.Data.SqlClient"/>
  </connectionStrings>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.net>
    <settings>
      <servicePointManager expect100Continue="false"/>
    </settings>
  </system.net>
  <system.serviceModel>
    <diagnostics>
    <messageLogging
         logEntireMessage="true"
         logMalformedMessages="true"
         logMessagesAtServiceLevel="true"
         logMessagesAtTransportLevel="true"
         maxMessagesToLog="3000000"
         maxSizeOfMessageToLog="2000000"/>
  </diagnostics>

    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IEntitySearchWcf" maxBufferSize="10000000" maxReceivedMessageSize="10000000" closeTimeout="00:20:00" openTimeout="00:20:00" receiveTimeout="00:20:00" sendTimeout="00:20:00" />
        <binding name="BasicHttpBinding_IBrokerWcf" maxBufferSize="6500000" maxReceivedMessageSize="6500000" />
        <binding name="BasicHttpBinding_IProjectWcf" maxBufferSize="9900000" maxReceivedMessageSize="9900000" />
        <binding name="BasicHttpBinding_ILoginWcf" maxReceivedMessageSize="20000000" maxBufferSize="20000000" /> 
        <binding name="BasicHttpBinding_ISupportWcf" maxBufferSize="9900000" maxReceivedMessageSize="9900000" />
        <binding name="BasicHttpBinding_IInscoWcf" maxBufferSize="100000000" maxReceivedMessageSize="100000000" />
        <binding name="BasicHttpBinding_IClientMaintenanceWcf" maxReceivedMessageSize="9900000" />
        <binding name="BasicHttpBinding_IWebUserWcf" maxReceivedMessageSize="9900000" />
        <binding name="BasicHttpBinding_IRoleWcf" maxReceivedMessageSize="9900000" />
        <binding name="BasicHttpBinding_ILabelWcf" maxReceivedMessageSize="10000000" maxBufferSize="10000000" />
        <binding name="BasicHttpBinding_IProjectTypeWcfSvc" maxReceivedMessageSize="9900000" />
        <binding name="BasicHttpBinding_IDropDownWcf" maxBufferSize="100000000" maxReceivedMessageSize="100000000" />
        <binding name="BasicHttpBinding_IDefaultCertLimitWcf" maxBufferSize="100000000" maxReceivedMessageSize="100000000" />
        <binding name="BasicHttpBinding_IConfigurationWcf" />
        <binding name="BasicHttpBinding_IEndorsementsWcf" />
        <binding name="BasicHttpBinding_IProjectCertReqWcf" maxBufferSize="2000000000" maxReceivedMessageSize="2000000000" />
        <binding name="BasicHttpBinding_IInsuredEntryWcf" maxBufferSize="1000000000" maxReceivedMessageSize="1000000000" />
        <binding name="BasicHttpBinding_ICertWcf" maxBufferSize="1000000000" maxReceivedMessageSize="1000000000" />
        <binding name="BasicHttpBinding_IDocumentWcf" maxBufferSize="1000000000" maxReceivedMessageSize="1000000000" />
        <binding name="BasicHttpBinding_IReportsWcf" />
        <binding name="BasicHttpBinding_ICertGenLetterTemplWcf" />
        <binding name="BasicHttpBinding_IGenerateLetterWcf" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"  
                 closeTimeout="00:20:00" openTimeout="00:20:00" receiveTimeout="00:20:00" sendTimeout="00:20:00" 
                 />
        <binding name="BasicHttpBinding_ILinkImagesWcf" maxBufferSize="1000000000" maxReceivedMessageSize="1000000000" />
        <binding name="BasicHttpBinding_IErrorLogWcf" />
        <binding name="BasicHttpBinding_IDashBoardWcf" />
        <binding name="BasicHttpBinding_IReviewScannedCertificateWcf" maxBufferSize="1000000000" maxReceivedMessageSize="1000000000" />
        <binding name="BasicHttpBinding_IAllEndorsementsWcf" />
        <binding name="BasicHttpBinding_IScanDocumentWcf" />
        <binding name="BasicHttpBinding_IUserWcf" />
        <binding name="BasicHttpBinding_IOutputLogWcf" />
        <binding name="BasicHttpBinding_IStreamServiceWcf" closeTimeout="00:20:00"
            openTimeout="00:20:00" receiveTimeout="00:20:00" sendTimeout="00:20:00"
            maxBufferPoolSize="2147483647" maxBufferSize="2147483647"
            maxReceivedMessageSize="2147483647" transferMode="Streamed" messageEncoding="Mtom"/>        
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:61394/EntitySearchWcf.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IEntitySearchWcf" contract="EntitySearchWcfSvc.IEntitySearchWcf" name="BasicHttpBinding_IEntitySearchWcf" />
      <endpoint address="http://localhost:61394/BrokerWcf.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IBrokerWcf" contract="BrokerWcfSvc.IBrokerWcf" name="BasicHttpBinding_IBrokerWcf" />
      <endpoint address="http://localhost:61394/ProjectWcf.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IProjectWcf" contract="ProjectWcfSvc.IProjectWcf" name="BasicHttpBinding_IProjectWcf" />
      <endpoint address="http://localhost:61394/SupportWcf.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISupportWcf" contract="SupportWcfSvc.ISupportWcf" name="BasicHttpBinding_ISupportWcf" />
      <endpoint address="http://localhost:61394/LoginWcf.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ILoginWcf" contract="LoginWcfSvc.ILoginWcf" name="BasicHttpBinding_ILoginWcf" />
      <endpoint address="http://localhost:61394/InscoWcf.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IInscoWcf" contract="InscoWcfSvc.IInscoWcf" name="BasicHttpBinding_IInscoWcf" />
      <endpoint address="http://localhost:61394/ClientMaintenanceWcf.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IClientMaintenanceWcf" contract="ClientMaintenanceWcfSvc.IClientMaintenanceWcf" name="BasicHttpBinding_IClientMaintenanceWcf" />
      <endpoint address="http://localhost:61394/WebUserWcf.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IWebUserWcf" contract="WebUserWcfSvc.IWebUserWcf" name="BasicHttpBinding_IWebUserWcf" />
      <endpoint address="http://localhost:61394/RoleWcf.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IRoleWcf" contract="RoleWcfSvc.IRoleWcf" name="BasicHttpBinding_IRoleWcf" />
      <endpoint address="http://localhost:61394/LabelWcf.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ILabelWcf" contract="LabelWcfSvc.ILabelWcf" name="BasicHttpBinding_ILabelWcf" />
      <endpoint address="http://localhost:61394/ProjectTypeWcfSvc.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IProjectTypeWcfSvc" contract="ProjectTypeWcfSvc.IProjectTypeWcfSvc" name="BasicHttpBinding_IProjectTypeWcfSvc" />
      <endpoint address="http://localhost:61394/DefaultCertLimitWcf.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IDefaultCertLimitWcf" contract="DefaultCertLimitWcfSvc.IDefaultCertLimitWcf" name="BasicHttpBinding_IDefaultCertLimitWcf" />
      <endpoint address="http://localhost:61394/DropDownWcf.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IDropDownWcf" contract="DropDownWcfSvc.IDropDownWcf" name="BasicHttpBinding_IDropDownWcf" />
      <endpoint address="http://localhost:61394/ConfigurationWcf.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IConfigurationWcf" contract="ConfigurationWcfSvc.IConfigurationWcf" name="BasicHttpBinding_IConfigurationWcf" />
      <endpoint address="http://localhost:61394/EndorsementsWcf.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IEndorsementsWcf" contract="EndorsementsWcfSvc.IEndorsementsWcf" name="BasicHttpBinding_IEndorsementsWcf" />
      <endpoint address="http://localhost:61394/ProjectCertReqWcf.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IProjectCertReqWcf" contract="ProjectCertReqWcfSvc.IProjectCertReqWcf" name="BasicHttpBinding_IProjectCertReqWcf" />
      <endpoint address="http://localhost:61394/InsuredEntryWcf.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IInsuredEntryWcf" contract="InsuredEntryWcfSvc.IInsuredEntryWcf" name="BasicHttpBinding_IInsuredEntryWcf" />
      <endpoint address="http://localhost:61394/CertWcf.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICertWcf" contract="CertWcfSvc.ICertWcf" name="BasicHttpBinding_ICertWcf" />
      <endpoint address="http://localhost:61394/DocumentWcf.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IDocumentWcf" contract="DocumentWcfSvc.IDocumentWcf" name="BasicHttpBinding_IDocumentWcf" />
      <endpoint address="http://localhost:61394/ReportsWcf.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IReportsWcf" contract="ReportsWcfSvc.IReportsWcf" name="BasicHttpBinding_IReportsWcf" />
      <endpoint address="http://localhost:61394/CertGenLetterTemplWcf.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICertGenLetterTemplWcf" contract="CertGenLetterTemplWcfSvc.ICertGenLetterTemplWcf" name="BasicHttpBinding_ICertGenLetterTemplWcf" />
      <endpoint address="http://localhost:61394/GenerateLetterWcf.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IGenerateLetterWcf" contract="GenerateLetterWcfSvc.IGenerateLetterWcf" name="BasicHttpBinding_IGenerateLetterWcf" />
      <endpoint address="http://localhost:61394/LinkImagesWcf.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ILinkImagesWcf" contract="LinkImagesWcfSvc.ILinkImagesWcf" name="BasicHttpBinding_ILinkImagesWcf" />
      <endpoint address="http://localhost:61394/ErrorLogWcf.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IErrorLogWcf" contract="ErrorLogWcfSvc.IErrorLogWcf" name="BasicHttpBinding_IErrorLogWcf" />
      <endpoint address="http://localhost:61394/DashBoardWcf.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IDashBoardWcf" contract="DashboardWcfSvc.IDashBoardWcf" name="BasicHttpBinding_IDashBoardWcf" />
      <endpoint address="http://localhost:61394/ReviewScannedCertificateWcf.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IReviewScannedCertificateWcf" contract="ReviewScannedCertificateWcfSvc.IReviewScannedCertificateWcf" name="BasicHttpBinding_IReviewScannedCertificateWcf" />
      <endpoint address="http://localhost:61394/AllEndorsementsWcf.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IAllEndorsementsWcf" contract="AllEndorsementsWcfSvc.IAllEndorsementsWcf" name="BasicHttpBinding_IAllEndorsementsWcf" />
      <endpoint address="http://localhost:61394/ScanDocumentWcf.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IScanDocumentWcf" contract="ScanDocumentWcfSvc.IScanDocumentWcf" name="BasicHttpBinding_IScanDocumentWcf" />
      <endpoint address="http://localhost:61394/UserWcf.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IUserWcf" contract="UserWcfSvc.IUserWcf" name="BasicHttpBinding_IUserWcf" />
      <endpoint address="http://localhost:61394/OutputLogWcf.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IOutputLogWcf" contract="OutputLogWcfSvc.IOutputLogWcf" name="BasicHttpBinding_IOutputLogWcf" />
      <endpoint address="http://localhost:61394/StreamServiceWcf.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IStreamServiceWcf" contract="StreamServiceWcfSvc.IStreamServiceWcf" name="BasicHttpBinding_IStreamServiceWcf" />
    </client>
    <behaviors>
      <serviceBehaviors>
        <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"/>
          <dataContractSerializer maxItemsInObjectGraph="1365536" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true"  />
    <standardEndpoints>
      <webHttpEndpoint>
        <standardEndpoint name="" helpEnabled="true"   maxReceivedMessageSize="65536000"/>
      </webHttpEndpoint>
    </standardEndpoints>  
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>

  </system.webServer>


  <system.diagnostics>
    <trace autoflush="true" />
    <sources>
      <source name="System.ServiceModel.MessageLogging">
        <listeners>
          <add name="messages"
              type="System.Diagnostics.XmlWriterTraceListener"
              initializeData="c:\logs\messages.svclog" />
        </listeners>
      </source>
      <source name="System.ServiceModel"
              switchValue="Warning, Critical, Error, Verbose"
              propagateActivity="true">
        <listeners>
          <add name="sdt"
              type="System.Diagnostics.XmlWriterTraceListener"
              initializeData= "c:\logs\service.svclog" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>

</configuration>

1 个答案:

答案 0 :(得分:0)

我对您目前的配置有疑问。为什么在端点地址中使用绝对服务地址?如果服务托管在IIS中,则基址由IIS站点绑定模块提供。
enter image description here
因此,我怀疑当前的实时连接未使用此端点地址,这导致MaxReceivedMessageSize设置失败。我想知道客户端实际使用的服务地址是什么。仅在正确的服务端点地址上应用配置才能生效。
已更新。
似乎上面的配置在客户端,下面的配置在服务器端。此外,WCF服务包含多个服务合同。
服务器端的配置未明确声明服务的创建方式。配置文件中既没有“服务”部分,也没有“协议映射”部分。像下面的表格。

    <services>
      <service name="ConsoleApp3.TestService">
        <endpoint address="" binding="basicHttpBinding" contract="ConsoleApp3.ITestService" ></endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>
      </service>
</services>

然后

<protocolMapping>
      <add binding="webHttpBinding" scheme="http"/>
</protocolMapping>

即,它使用默认的Basichttpbinding创建服务。无法将设置应用于正确的服务端点。
我建议您在服务器端尝试以下配置。

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="mybinding" maxBufferSize="20000000" maxReceivedMessageSize="2147483647" >
          <readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <protocolMapping>
      <add binding="basicHttpBinding" scheme="http" bindingConfiguration="mybinding"/>
    </protocolMapping>
  </system.serviceModel>

它还可以支持多个服务合同。
随时让我知道问题是否仍然存在。

相关问题