private byte[] getLayerCountByType(System.Collections.Specialized.NameValueCollection boundVariables,
                                           ESRI.ArcGIS.SOESupport.JsonObject operationInput,
                                           string outputFormat,
                                           string requestProperties,
                                           out string responseProperties)
        {
            IMapImage mapImage = null;

            bool?shouldAdd = null;

            operationInput.TryGetAsBoolean("addlayer", out shouldAdd);

            if (shouldAdd.HasValue)
            {
                if ((bool)shouldAdd)
                {
                    if (((IMapServerInfo4)mapServerInfo).SupportsDynamicLayers)
                    {
                        IRgbColor color = new RgbColor()
                        {
                            Blue = 255
                        };

                        ISimpleLineSymbol outline = new SimpleLineSymbol()
                        {
                            Color = color,
                            Width = 1,
                            Style = esriSimpleLineStyle.esriSLSSolid
                        };

                        ISimpleFillSymbol sfs = new SimpleFillSymbol()
                        {
                            Color   = color,
                            Outline = outline,
                            Style   = esriSimpleFillStyle.esriSFSSolid
                        };

                        ISimpleRenderer sr = new SimpleRenderer()
                        {
                            Symbol = (ISymbol)sfs
                        };

                        IFeatureLayerDrawingDescription featureLayerDrawingDesc = new FeatureLayerDrawingDescription()
                        {
                            FeatureRenderer = (IFeatureRenderer)sr
                        };

                        IMapServerSourceDescription mapServerSourceDesc = new TableDataSourceDescriptionClass();
                        ((IDataSourceDescription)mapServerSourceDesc).WorkspaceID    = "MyFGDB";
                        ((ITableDataSourceDescription)mapServerSourceDesc).TableName = "B";

                        IDynamicLayerDescription dynamicLayerDesc = new LayerDescriptionClass()
                        {
                            ID                 = 3,
                            Visible            = true,
                            DrawingDescription = (ILayerDrawingDescription)featureLayerDrawingDesc,
                            Source             = mapServerSourceDesc
                        };

                        mapDesc.HonorLayerReordering = true;
                        mapDesc.LayerDescriptions.Insert(0, (ILayerDescription)dynamicLayerDesc);

                        mapImage = exportMap();
                    }
                }
                else
                {
                    mapImage = exportMap();
                }
            }
            responseProperties = null;

            JSONObject json = new JSONObject();

            json.AddString("URL", mapImage.URL);
            return(Encoding.UTF8.GetBytes(json.ToJSONString(null)));
        }
        private byte[] getLayerCountByType(System.Collections.Specialized.NameValueCollection boundVariables,
            ESRI.ArcGIS.SOESupport.JsonObject operationInput,
            string outputFormat,
            string requestProperties,
            out string responseProperties) 
        {
            IMapImage mapImage = null;

            bool? shouldAdd = null;
            operationInput.TryGetAsBoolean("addlayer", out shouldAdd);

            if (shouldAdd.HasValue)
            {
                if ((bool)shouldAdd)
                {
                    if (((IMapServerInfo4)mapServerInfo).SupportsDynamicLayers)
                    {
                        IRgbColor color = new RgbColor(){ Blue = 255};

                        ISimpleLineSymbol outline = new SimpleLineSymbol(){ 
                            Color = color, 
                            Width = 1, 
                            Style = esriSimpleLineStyle.esriSLSSolid
                        };

                        ISimpleFillSymbol sfs = new SimpleFillSymbol(){ 
                            Color = color, 
                            Outline = outline, 
                            Style = esriSimpleFillStyle.esriSFSSolid
                        };
                        
                        ISimpleRenderer sr = new SimpleRenderer(){ Symbol = (ISymbol)sfs };

                        IFeatureLayerDrawingDescription featureLayerDrawingDesc = new FeatureLayerDrawingDescription(){
                            FeatureRenderer = (IFeatureRenderer)sr
                        };

                        IMapServerSourceDescription mapServerSourceDesc = new TableDataSourceDescriptionClass();
                        ((IDataSourceDescription)mapServerSourceDesc).WorkspaceID = "MyFGDB";
                        ((ITableDataSourceDescription)mapServerSourceDesc).TableName = "B";

                        IDynamicLayerDescription dynamicLayerDesc = new LayerDescriptionClass(){
                            ID = 3,
                            Visible = true,
                            DrawingDescription = (ILayerDrawingDescription)featureLayerDrawingDesc,
                            Source = mapServerSourceDesc
                        };

                        mapDesc.HonorLayerReordering = true;
                        mapDesc.LayerDescriptions.Insert(0, (ILayerDescription)dynamicLayerDesc);

                        mapImage = exportMap();
                    }    
                }
                else
                {
                    mapImage = exportMap();
                }
            }
            responseProperties = null; 
  
        	JSONObject json = new JSONObject();
            json.AddString("URL", mapImage.URL);
            return Encoding.UTF8.GetBytes(json.ToJSONString(null));
        }