public static string ApplyMLClassifyFunction(IImageServer imageServer, IRaster pRaster, string signaturfile)
        {
            //Define a  function.
            IRasterFunction hillshadeFunction = new MLClassifyFunctionClass();

            IRasterFunctionArguments functionArgument = new MLClassifyFunctionArgumentsClass();
            functionArgument.PutValue("Raster", pRaster);
            functionArgument.PutValue("SignatureFile", signaturfile);

            //Attach the function to a rendering rule.
            IRenderingRule renderRule = new RenderingRuleClass();
            renderRule.Function = hillshadeFunction;
            renderRule.Arguments = functionArgument;
            renderRule.VariableName = "DEM";

            //Define the image description.
            IGeoImageDescription geoImageDesc = new GeoImageDescriptionClass();
            geoImageDesc.Compression = "LZ77";
            geoImageDesc.Extent = imageServer.ServiceInfo.Extent;
            geoImageDesc.Width = 800;
            geoImageDesc.Height = 600;
            geoImageDesc.Interpolation = rstResamplingTypes.RSP_BilinearInterpolation;
            IGeoImageDescription2 geoImageDesc2 = (IGeoImageDescription2)geoImageDesc;

            geoImageDesc2.RenderingRule = renderRule;

            //Define the return image type.
            IImageType imgType = new ImageTypeClass();
            imgType.Format = esriImageFormat.esriImagePNG;
            imgType.ReturnType = esriImageReturnType.esriImageReturnURL;

            //Export the image.
            IImageResult imgResult = imageServer.ExportImage(geoImageDesc2, imgType);
            return imgResult.URL;
        }
        public static string GetAndApplyColormap(IImageServer imageServer)
        {
            //Get the color map.
            IImageServiceInfo3 isInfo = imageServer.ServiceInfo as IImageServiceInfo3;
            IRasterColormap colormap = isInfo.Colormap;
            //Create the color map function using the color map.
            IRenderingRule rule = new RenderingRuleClass();
            ColormapFunction colormapfunction = new ColormapFunctionClass();
            IColormapFunctionArguments colormapargs = new ColormapFunctionArgumentsClass();
            colormapargs.Colormap = colormap;
            rule.Function = colormapfunction;
            rule.Arguments = (IRasterFunctionArguments)colormapargs;
            rule.VariableName = "Raster";    //Define export image request.
            IGeoImageDescription2 geoImageDesc = new GeoImageDescriptionClass();
            geoImageDesc.Width = 800;
            geoImageDesc.Height = 600;
            geoImageDesc.Extent = isInfo.Extent;
            geoImageDesc.RenderingRule = rule;

            //Export an image using service's color map.
            IImageType imageType = new ImageTypeClass();
            imageType.Format = esriImageFormat.esriImageJPGPNG;
            imageType.ReturnType = esriImageReturnType.esriImageReturnURL;
            IMapImage mapImage = ((IImageServer2)imageServer).ExportMapImage(geoImageDesc, imageType);
            return mapImage.URL;
        }