2014-01-02 4 views
2

Я получил эту ошибку при попытке передать большие байты [], чтобы ФОС службе моего IService Кода:WCF Service Error 413 "Entity Too Large", когда передача большие байты []

[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); 

Service Код:

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

ФОС службы Config:

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

Пожалуйста, любой один помочь мне решить эту проблему я увеличил UploadReadAheadSize на iis7, но до сих пор не работает я хочу знать, почему этот код не работает

+1

Проверьте [Request Entity Too Large] (http://stackoverflow.com/questions/14636407/maxreceivedmessagesize-not-fixing-413-request-entity-too-large) и этот [Request Entity Too Large] (http://stackoverflow.com/questions/10122957/iis7-413-request-entity-too-large-uploadreadaheadsize) – Ravi

+0

Можете ли вы добавить конфигурацию конечной точки с сервера? – rene

+0

Я добавил его, но все еще не работал –

ответ

4

Связывание вы определили в файле конфигурации («basicHttpBindingSettings») не используется службой WCF, потому что вы делаете не имеет определенной конечной точки, которая ее использует. С 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> 

Это будет тогда конфигурация по умолчанию для basicHttpBinding.

Второй вариант состоит в определении явного конечной точки и присвоить конфигурацию привязки к нему с помощью атрибута bindingConfiguration, как это:

<services> 
    <service name="<service name>"> 
    <endpoint address="" binding="basicHttpBinding" 
       bindingConfiguration="basicHttpBindingSettings" 
       contract="<fully qualified contract name>" /> 
    </service> 
</services> 

Для получения дополнительной информации по умолчанию конечных точек и привязки см A Developer's Introduction to Windows Communication Foundation 4.