/// <summary>Initializes the service configuration.</summary>
        public static void InitializeService(IDataServiceConfiguration configuration)
        {
            APICallLog.Current.DataService.InitializeService("TestDataWebService");
            //Because the configuration settings can be deliberately messed up on the server-side before calling ClearAll() ,
            //we need this to be the first step in the InitializeService
            ClearAllIfRequired();
            try
            {
                foreach (string setting in configurationSettings.PropertySetList)
                {
                    if (setting == "UseVerboseErrors")
                    {
                        configuration.UseVerboseErrors = configurationSettings.UseVerboseErrors;
                    }

                    else if (setting == "MaxBatchCount")
                    {
                        configuration.MaxBatchCount = configurationSettings.MaxBatchCount;
                    }

                    else if (setting == "MaxChangesetCount")
                    {
                        configuration.MaxChangesetCount = configurationSettings.MaxChangesetCount;
                    }

                    else if (setting == "MaxExpandCount")
                    {
                        configuration.MaxExpandCount = configurationSettings.MaxExpandCount;
                    }

                    else if (setting == "MaxExpandDepth")
                    {
                        configuration.MaxExpandDepth = configurationSettings.MaxExpandDepth;
                    }

                    else if (setting == "MaxObjectCountOnInsert")
                    {
                        configuration.MaxObjectCountOnInsert = configurationSettings.MaxObjectCountOnInsert;
                    }

                    else if (setting == "MaxResultsPerCollection")
                    {
                        configuration.MaxResultsPerCollection = configurationSettings.MaxResultsPerCollection;
                    }
                }

                foreach (string entity in configurationSettings.EntitySetAccessRules.Keys)
                {
                    configuration.SetEntitySetAccessRule(entity, configurationSettings.EntitySetAccessRules[entity]);
                }

                foreach (string entity in configurationSettings.ServiceOperationAccessRules.Keys)
                {
                    configuration.SetServiceOperationAccessRule(entity, configurationSettings.ServiceOperationAccessRules[entity]);
                }

                MethodInfo mi = configuration.GetType().GetMethod("SetEntitySetPageSize", BindingFlags.Instance | BindingFlags.Public);
                if (mi != null)
                {
                    foreach (string entity in configurationSettings.EntitySetPageSizes.Keys)
                    {
                        mi.Invoke(configuration, new object[] { entity, configurationSettings.EntitySetPageSizes[entity] });
                    }
                }

                foreach (string type in configurationSettings.KnownTypesToRegister)
                {
                    Type t = Type.GetType(type);

                    if (t == null)
                    {
                        t = typeof(TestDataWebService <>).Assembly.GetType(type);
                    }

                    if (t == null)
                    {
                        throw new DataServiceException(500, "Could not resolve type with name '" + type + "'");
                    }

                    configuration.RegisterKnownType(t);
                }

                MethodInfo enableTypeAccess = configuration.GetType().GetMethod("EnableTypeAccess", BindingFlags.Instance | BindingFlags.Public);
                if (enableTypeAccess != null)
                {
                    // Note: the provider wrapper for IDSMP is strict about calls to TryResolveResourceType.
                    // However, the DataServiceConfiguration.EnableTypeAccess method does not cache resolved types,
                    // so we need to explicitly turn off the extra validation before calling it.
                    bool oldValue = MetadataProviderWrapper.ValidateTypeResolution;
                    try
                    {
                        MetadataProviderWrapper.ValidateTypeResolution = false;
                        foreach (string typeName in configurationSettings.EnableAccessToTypes)
                        {
                            enableTypeAccess.Invoke(configuration, new object[] { typeName });
                        }
                    }
                    finally
                    {
                        // make sure to turn the validation back on, if it was on
                        MetadataProviderWrapper.ValidateTypeResolution = oldValue;
                    }
                }

                if (configuration.GetType().Name == "DataServiceConfiguration")
                {
                    PropertyInfo dsb = configuration.GetType().GetProperty("DataServiceBehavior");
                    if (dsb != null)
                    {
                        object dataServiceBevhaior = dsb.GetValue(configuration, null);
                        if (dataServiceBevhaior != null)
                        {
                            Type dataServiceBehaviorType = dataServiceBevhaior.GetType();

                            if (configurationSettings.PropertySetList.Contains("AllowCountRequests"))
                            {
                                PropertyInfo propertyInfo = dataServiceBehaviorType.GetProperty("AcceptCountRequests");
                                propertyInfo.SetValue(dataServiceBevhaior, configurationSettings.AllowCountRequests, null);
                            }

                            if (configurationSettings.PropertySetList.Contains("AllowProjectionRequests"))
                            {
                                PropertyInfo propertyInfo = dataServiceBehaviorType.GetProperty("AcceptProjectionRequests");
                                propertyInfo.SetValue(dataServiceBevhaior, configurationSettings.AllowProjectionRequests, null);
                            }

                            if (configurationSettings.PropertySetList.Contains("InvokeInterceptorsOnLinkDelete"))
                            {
                                PropertyInfo propertyInfo = dataServiceBehaviorType.GetProperty("InvokeInterceptorsOnLinkDelete");
                                propertyInfo.SetValue(dataServiceBevhaior, configurationSettings.InvokeInterceptorsOnLinkDelete, null);
                            }

                            if (configurationSettings.PropertySetList.Contains("MaxProtocolVersion") && configurationSettings.MaxProtocolVersion.HasValue)
                            {
                                PropertyInfo propertyInfo = dataServiceBehaviorType.GetProperty("MaxProtocolVersion");
                                propertyInfo.SetValue(dataServiceBevhaior, configurationSettings.MaxProtocolVersion, null);
                            }
                        }
                    }
                    //
                    //object
                }
            }
            catch (Exception excpt)
            {
                if (!ClearAllIfRequired())
                {
                    throw new DataServiceException(excpt.ToString(), excpt);
                }
            }
            finally
            {
                APICallLog.Current.Pop();
            }
        }