C# 传递大字节[]时WCF服务错误413“实体太大”

C# 传递大字节[]时WCF服务错误413“实体太大”,c#,asp.net,.net,wcf,wcf-rest,C#,Asp.net,.net,Wcf,Wcf Rest,我在尝试将大字节[]传递给wcf服务时遇到此错误 我的设备代码: [OperationContract] [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json, UriTemplate = "SaveFile")] SaveFileResult SaveFile(byte[] FileByt

我在尝试将大字节[]传递给wcf服务时遇到此错误 我的设备代码:

[OperationContract]
        [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json, UriTemplate = "SaveFile")]
        SaveFileResult SaveFile(byte[] FileBytes, string FileName, decimal Filesize, string IntegrationSystem, string TellerIndentity, string SendingOfficeCode, string SendingArea);
public SaveFileResult SaveFile(byte[] FileBytes, string FileName, decimal Filesize, string IntegrationSystem, string TellerIndentity, string SendingOfficeCode, string SendingArea)
        {
            FileFactory _FileFactory = new FileFactory();
            string _strExt = Path.GetExtension(FileName);
            IFileDealer _IFileDealer = _FileFactory.GetFileDealer(_strExt);
            SaveFileResult _Result=_IFileDealer.SaveFile(FileBytes, FileName, Filesize, IntegrationSystem, TellerIndentity, SendingOfficeCode, SendingArea);
            return _Result;
        }
服务代码:

[OperationContract]
        [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json, UriTemplate = "SaveFile")]
        SaveFileResult SaveFile(byte[] FileBytes, string FileName, decimal Filesize, string IntegrationSystem, string TellerIndentity, string SendingOfficeCode, string SendingArea);
public SaveFileResult SaveFile(byte[] FileBytes, string FileName, decimal Filesize, string IntegrationSystem, string TellerIndentity, string SendingOfficeCode, string SendingArea)
        {
            FileFactory _FileFactory = new FileFactory();
            string _strExt = Path.GetExtension(FileName);
            IFileDealer _IFileDealer = _FileFactory.GetFileDealer(_strExt);
            SaveFileResult _Result=_IFileDealer.SaveFile(FileBytes, FileName, Filesize, IntegrationSystem, TellerIndentity, SendingOfficeCode, SendingArea);
            return _Result;
        }
wcf服务配置:

<?xml version="1.0"?>
<configuration>
  <connectionStrings>
    <add name="CenterPostEntities" connectionString="metadata=res://*/DatabaseDesign.GRemModel.csdl|res://*/DatabaseDesign.GRemModel.ssdl|res://*/DatabaseDesign.GRemModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=TEST-SH\SQL2005;initial catalog=CenterPost;user id=sa;password=itsc;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <appSettings>
    <add key="PermittedFastUploadSize"  value="1000000"/>
    <add  key ="GRemLog" value="d:\GRemLog"/>
    <add key="FileUploadPath" value="d:\FileUpload"/>
  </appSettings>
    <system.web>
    <compilation debug="true" targetFramework="4.0" />
      <httpRuntime maxRequestLength="2097151" />
  </system.web>
  <system.serviceModel>
    <!--======================-->
    <bindings>
      <basicHttpBinding>
        <binding name="basicHttpBindingSettings"  openTimeout="00:01:00" receiveTimeout="05:00:00" sendTimeout="05:00:00" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647777" messageEncoding="Text">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
          <!-- 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>
    </behaviors>
    <!--======================-->
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
   <serverRuntime enabled="true" uploadReadAheadSize="2147483647"  />
  </system.webServer>
请任何人帮我解决这个问题 我在iis7上增加了uploadReadAheadSize,但仍然不起作用
我想知道为什么此代码不起作用

WCF服务没有使用您在配置文件basicHttpBindingSettings中定义的绑定,因为您没有定义使用它的端点。对于WCF 4.0+,如果配置文件中没有定义端点,则将创建默认端点,并且开箱即用,绑定将是具有默认值的basicHttpBinding

有两种方法可以解决这个问题

首先,可以通过省略name属性使绑定定义成为默认定义,如下所示:

<bindings>
  <basicHttpBinding>
    <binding openTimeout="00:01:00" receiveTimeout="05:00:00" 
             sendTimeout="05:00:00" maxReceivedMessageSize="2147483647"
             maxBufferPoolSize="2147483647777" messageEncoding="Text">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                    maxArrayLength="2147483647" maxBytesPerRead="2147483647"
                    maxNameTableCharCount="2147483647" />
    </binding>
  </basicHttpBinding>
</bindings>
<services>
  <service name="<service name>">
    <endpoint address="" binding="basicHttpBinding"
              bindingConfiguration="basicHttpBindingSettings"
              contract="<fully qualified contract name>" />
  </service>
</services>

有关默认端点和绑定的详细信息,请参阅。

WCF服务未使用您在配置文件basicHttpBindingSettings中定义的绑定,因为您没有定义使用该绑定的端点。对于WCF 4.0+,如果配置文件中没有定义端点,则将创建默认端点,并且开箱即用,绑定将是具有默认值的basicHttpBinding

有两种方法可以解决这个问题

首先,可以通过省略name属性使绑定定义成为默认定义,如下所示:

<bindings>
  <basicHttpBinding>
    <binding openTimeout="00:01:00" receiveTimeout="05:00:00" 
             sendTimeout="05:00:00" maxReceivedMessageSize="2147483647"
             maxBufferPoolSize="2147483647777" messageEncoding="Text">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                    maxArrayLength="2147483647" maxBytesPerRead="2147483647"
                    maxNameTableCharCount="2147483647" />
    </binding>
  </basicHttpBinding>
</bindings>
<services>
  <service name="<service name>">
    <endpoint address="" binding="basicHttpBinding"
              bindingConfiguration="basicHttpBindingSettings"
              contract="<fully qualified contract name>" />
  </service>
</services>

有关默认端点和绑定的详细信息,请参阅。

签出此项,您可以从服务器添加端点配置吗?我添加了它但仍不工作签出此项,您可以从服务器添加端点配置吗?我添加了它但仍不工作