locked
how to set increase WCF response size ? RRS feed

  • Question

  • User146144033 posted

    Hi

    My WCF webservice returns a large array of around 20000 records via a simple GET.

    However above 8175 records the GET request  fails witha 400 Bad request.

    I'd prefer not to use pages but just return 1 large array.

    I think I need to increase the buffer or stream it perhaps and change the web.config settings but I'm not sure how to connect everything.

    Any suggestions ?

    Here's my web.config

    <?xml version="1.0"?>
    
    <!--
      For more information on how to configure your ASP.NET application, please visit
      http://go.microsoft.com/fwlink/?LinkId=169433
      -->
    
    <configuration>
    	<system.webServer>
    		<handlers>
    			<remove name="ChartImageHandler"/>
    			<add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD,POST" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    		</handlers>
    		<security>
    		<authentication>
    			<basicAuthentication enabled="false" />
    		</authentication>
    		</security>
    	</system.webServer>
    	
         
         <connectionStrings>
    		
    	</connectionStrings>
         
         
    	<system.net>
    		<mailSettings>
    			<smtp>
    				<network host="localhost" port="25"/>
    			</smtp>			
    		</mailSettings>
    	</system.net>
    	<system.web>
              <httpRuntime maxRequestLength="10000"/>
    		<!--Set the locale for Australia for datetimes etc.-->
    		<globalization uiCulture="en" culture="en-AU"/>
    		<!-- 
                Set compilation debug="true" to insert debugging 
                symbols into the compiled page. Because this 
                affects performance, set this value to true only 
                during development.
            -->
    		<compilation debug="true" targetFramework="4.0">
    			<assemblies>
    				<add assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    			</assemblies>
    		</compilation>
    		
    		<!--
                The <authentication> section enables configuration 
                of the security authentication mode used by 
                ASP.NET to identify an incoming user. 
            -->
    		<authentication mode="Forms">
    			<forms loginUrl="login.aspx" timeout="60" defaultUrl="/manage/SelectCompany.aspx"/>
    		</authentication>
    		<machineKey validationKey="95FC4A5BA16C69A5BAF6B10A2EBCF88C1B8C77B5DA77D0653F86594CF71ABB2CD627DAAF08568462721B55E939B2966ED7D631E57B9E32DF1A15E599DF0C39FE" decryptionKey="203C8644E31C908F57DF5BE7D9FFE6225EE0BDFDB6E47BC9E1291CD838DCDFE7" validation="SHA1" decryption="AES"/>
    		<sessionState timeout="60"/>
    		<!--
                The <customErrors> section enables configuration 
                of what to do if/when an unhandled error occurs 
                during the execution of a request. Specifically, 
                it enables developers to configure html error pages 
                to be displayed in place of a error stack trace.
    
            <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
                <error statusCode="403" redirect="NoAccess.htm" />
                <error statusCode="404" redirect="FileNotFound.htm" />
            </customErrors>
            -->
    		<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
    			<controls>
    				<add tagPrefix="ajaxToolkit" namespace="AjaxControlToolkit" assembly="AjaxControlToolkit"/>
    				<add tagPrefix="asp" namespace="System.Web.UI.DataVisualization.Charting" assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    			</controls>
    		</pages>
    	</system.web>
    
         <location path="~/manage/Items/UploadItems.aspx">
              <system.web>
                   <httpRuntime executionTimeout="6000"/>
              </system.web>
         </location>
    
         <system.serviceModel>
        
         <behaviors>    
              <serviceBehaviors>
                   <behavior name="">
                        <serviceMetadata httpGetEnabled="true" />
                        <serviceDebug includeExceptionDetailInFaults="false" />
                   </behavior>
              </serviceBehaviors>
         </behaviors>
              
         <serviceHostingEnvironment aspNetCompatibilityEnabled="true"   multipleSiteBindingsEnabled="true" />
    	     <standardEndpoints>
    		     <webHttpEndpoint>
    			     <standardEndpoint name="" helpEnabled="true"  maxReceivedMessageSize="65536000"/>
    		     </webHttpEndpoint>
         </standardEndpoints>
    
    
         <bindings />
         <client />
         </system.serviceModel>
    </configuration>
    


    The web service is below:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;
    using System.ServiceModel.Web;
    using Stocktakr.Business;
    using WebApp.AppCode;
    using System.ServiceModel.Activation;
    
    namespace WebApp.services
    {
    	// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "MobileItemHandler" in code, svc and config file together.
    	[ServiceContract]
    	[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    	public class MobileItemHandler
    	{	
              /// <summary>
              /// Note datetimes here are set to strings due to json limitations. In POS handler they are standard datetimes.
              /// </summary>
    
    		public class LocalItem
    		{
    			public string product_code;
    			public string product_barcode;
    			public string description;			
    			public string sale_price;		
    			public string quantity;		
    			public bool is_static;		
    			public string modified_datetime;
    		}
    
    		
    		public class LocalStocktakeTransaction
    		{
    		
    			public string product_code;		
    			public string product_barcode;		
    			public string description;		
    			public double quantity;		
    			public string person;		
    			public string stocktake_datetime;
    		}
    
    		
    		public class ItemResponse
    		{
    			public bool is_error;
    			public string errorMessage;
    			public List<LocalItem> localItems;
    			public List<LocalStocktakeTransaction> localStocktakeTransactions;
    			public int itemCount;
    		}         
    
    		[WebGet(UriTemplate = "/ItemCount/{id}/{password}", ResponseFormat = WebMessageFormat.Json)]
    		public ItemResponse GetItemCount(string id, string password)
    		{
    			var newResponse = new ItemResponse();
    
    			try
    			{
    				int storeID = int.Parse(id);
    
    				Store current_store = Store.GetStore(storeID);
    
    
    				if (current_store == null)
    				{
    					newResponse.is_error = true;
    					newResponse.errorMessage = "NoStore";
    
    				}
    				else
    				{
    					if (password != current_store.password)
    					{
    						newResponse.is_error = true;
    						newResponse.errorMessage = "IncorrectPassword";
    					}
    					else
    					{
    						newResponse.itemCount = current_store.GetItemCount();
    						newResponse.is_error = false;						
    					}
    				}
    			}
    			catch (Exception ex)
    			{
    				newResponse.is_error = true;
    				newResponse.errorMessage = ex.ToString();
    				LogHelper.WriteError(ex.ToString());
    			}
    			return newResponse;
    		}
    
    		[WebGet(UriTemplate = "/Items/{id}/{password}/{start}/{pagesize}",  ResponseFormat = WebMessageFormat.Json)]
    		public ItemResponse GetBatchItemsForStocktake(string id, string password, string start,string pagesize)
    		{
    			var newResponse = new ItemResponse();
    
    			try
    			{
    				int storeID = int.Parse(id);
    				int pageSize = Convert.ToInt32(pagesize);
    
    				Store current_store = Store.GetStore(storeID);
    
    
    				if (current_store == null)
    				{
    				     newResponse.is_error = true;
    				     newResponse.errorMessage = "NoStore";
    
    				}
    				else
    				{
    				     if (password != current_store.password)
    				     {
    				          newResponse.is_error = true;
    				          newResponse.errorMessage = "IncorrectPassword";
    				     }
    				     else
    				     {
    
    						var newList = new List<LocalItem>();
    						long startRowIndex = Convert.ToInt64(start);
    						long totalRows = 0;
    						foreach (var item in Item.GetItemsBystore_(storeID,startRowIndex, pageSize, out totalRows))
    						{
    							LocalItem newItem = new LocalItem();
    							newItem.product_code = item.product_code;
    							newItem.product_barcode = item.product_barcode;
    							newItem.description = item.description;
    							newItem.sale_price = item.sale_price.ToString("#0.00");
    							newItem.quantity = item.quantity.ToString();
    							newItem.is_static = item.is_static;
    							newItem.modified_datetime = item.modified_datetime.ToString("yyyy-MM-dd hh:mm:ss");
    							newList.Add(newItem);
    						}
    						newResponse.itemCount = (int)totalRows;
    						newResponse.is_error = false;
    						newResponse.localItems = newList;
    				     }
    				}
    			}
    			catch (Exception ex)
    			{
    				newResponse.is_error = true;
    				newResponse.errorMessage = ex.ToString();
    				LogHelper.WriteError(ex.ToString());
    			}
    			return newResponse;
    		}
    
              [WebGet(UriTemplate = "/Items/{id}/{password}", ResponseFormat = WebMessageFormat.Json)]
              public ItemResponse GetItemsForStocktake(string id, string password)
              {
                   var newResponse = new ItemResponse();
    
                   try
                   {
                        int storeID = int.Parse(id);
                       
                        Store current_store = Store.GetStore(storeID);
    
    
                        if (current_store == null)
                        {
                             newResponse.is_error = true;
                             newResponse.errorMessage = "NoStore";
    
                        }
                        else
                        {
                             if (password != current_store.password)
                             {
                                  newResponse.is_error = true;
                                  newResponse.errorMessage = "IncorrectPassword";
                             }
                             else
                             {
    
                                  var newList = new List<LocalItem>();
                                 
                                 
                                  foreach (var item in current_store.ItemsBystore_)
                                  {
                                       LocalItem newItem = new LocalItem();
                                       newItem.product_code = item.product_code;
                                       newItem.product_barcode = item.product_barcode;
                                       newItem.description = item.description;
                                       newItem.sale_price = item.sale_price.ToString("#0.00");
                                       newItem.quantity = item.quantity.ToString();
                                       newItem.is_static = item.is_static;
                                       newItem.modified_datetime = item.modified_datetime.ToString("yyyy-MM-dd hh:mm:ss");
                                       newList.Add(newItem);
                                  }
                                  newResponse.itemCount = current_store.ItemsBystore_.Count();
                                  newResponse.is_error = false;
                                  newResponse.localItems = newList;
                             }
                        }
                   }
                   catch (Exception ex)
                   {
                        newResponse.is_error = true;
                        newResponse.errorMessage = ex.ToString();
                        LogHelper.WriteError(ex.ToString());
                   }
                   return newResponse;
              }		
    	}
    }
    



    Sunday, April 22, 2012 8:59 AM

Answers

All replies