Trying to send an Array of size 1227136 and get error 413
This is how I send data from a wreb application -
protected void Page_Load(object sender, EventArgs e) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost:59624/RestServiceImpl.svc/PostFileRest");//Path for local request.Timeout = Timeout.Infinite; request.KeepAlive = true; request.ContentType = "application/vnd.ms-excel"; /*---------------------------------------------------------------------------*/ string excelTojson = excelToJson(); byte[] fileData = Encoding.ASCII.GetBytes(excelTojson); /*---------------------------------------------------------------------------*/ request.ContentLength = fileData.Length; Stream requestStream = request.GetRequestStream(); requestStream.Write(fileData, 0, fileData.Length); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); System.Diagnostics.Debug.Assert(response.StatusCode == HttpStatusCode.OK); string responseMessage = string.Empty; using (System.IO.StreamReader sr = new System.IO.StreamReader(response.GetResponseStream())) { responseMessage = sr.ReadToEnd(); } Response.Write(responseMessage); } #region excelToJson public string excelToJson() { var pathToExcel = @"E:\My_Work\MVC\Test1.xlsx"; OleDbConnection MyConnection; DataTable dt; OleDbDataAdapter MyCommand; MyConnection = new OleDbConnection("provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + pathToExcel + "';Extended Properties='Excel 12.0 Xml;HDR=YES'"); MyCommand = new System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection); MyCommand.TableMappings.Add("Table", "TestTable"); dt = new DataTable(); MyCommand.Fill(dt); MyConnection.Close(); string jsonString = string.Empty; return jsonString = JsonConvert.SerializeObject(dt); } #endregion
My WCF code is where I get data when sending a small amount of data, then it works fine. But I want to send big data.
[ServiceContract] public interface IRestServiceImpl { [OperationContract] [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "PostFileRest")] string PostFileRest(Stream fileContents); } public class RestServiceImpl : IRestServiceImpl { public string PostFileRest(Stream fileContents) { var httpRequest = HttpContext.Current.Request;
My app.config is
<?xml version="1.0"?>
<appSettings> <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" /> </appSettings> <system.web> <compilation debug="true" targetFramework="4.5.1" /> <httpRuntime targetFramework="4.5.1"/> <httpModules> </httpModules> </system.web> <system.serviceModel> <bindings> <basicHttpBinding> <binding name="myBinding" messageEncoding="Text" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" transferMode="Streamed" > <readerQuotas maxDepth="64" maxArrayLength="2147483647" maxStringContentLength="2147483647"/> </binding> </basicHttpBinding> </bindings> <services> <service behaviorConfiguration="ForecastREST_API.RESTServiceImplBehavior" name="ForecastREST_API.RestServiceImpl"> <endpoint address="http://localhost:59624/RestServiceImpl.svc" binding="webHttpBinding" contract="ForecastREST_API.IRestServiceImpl" behaviorConfiguration="Web"> <identity> </identity> </endpoint> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> </service> </services> <behaviors> <endpointBehaviors> <behavior name="Web"> <dataContractSerializer maxItemsInObjectGraph="2147483647" /> <webHttp defaultOutgoingResponseFormat="Json" automaticFormatSelectionEnabled="true" /> <dispatcherSynchronization asynchronousSendEnabled="true" /> </behavior> </endpointBehaviors> <serviceBehaviors> <behavior name="ForecastREST_API.RESTServiceImplBehavior"> <dataContractSerializer maxItemsInObjectGraph="2147483647" /> <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> </serviceBehaviors> </behaviors> <protocolMapping> <add binding="basicHttpsBinding" scheme="https" /> </protocolMapping> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="false" /> </system.serviceModel> <system.webServer> <modules runAllManagedModulesForAllRequests="true"/> <directoryBrowse enabled="true"/> </system.webServer>
source share