/**
         * This method returns the utility network dataset.
         */
        public IDataset GetUNDataset(IServerObject serverObject, string versionName = null)
        {
            IMapServer           mapService          = (MapServer)serverObject;
            IMapServerDataAccess mapServerDataAccess = (IMapServerDataAccess)serverObject;

            // Get feature class from any layer
            IFeatureClass fc = (IFeatureClass)mapServerDataAccess.GetDataSource(mapService.DefaultMapName, 0);

            // Get the container feature dataset
            IFeatureDataset fd = fc.FeatureDataset;

            // Open feature dataset in specified version
            if (!String.IsNullOrEmpty(versionName))
            {
                IWorkspace           workspace          = fd.Workspace;
                IVersionedWorkspace4 versionedWorkspace = (IVersionedWorkspace4)workspace;
                IVersion4            childVersion       = (IVersion4)versionedWorkspace.FindVersion(versionName);
                IFeatureWorkspace    childFWS           = (IFeatureWorkspace)childVersion;
                fd = childFWS.OpenFeatureDataset(fd.Name);
            }

            // Loop through contained datasets to find the UN one
            IDataset     ds        = (IDataset)fd;
            IEnumDataset enumSubDS = ds.Subsets;
            IDataset     subDS     = enumSubDS.Next();

            while (subDS != null)
            {
                if (subDS.Type == esriDatasetType.esriDTUtilityNetwork)
                {
                    return(subDS);
                }
                subDS = enumSubDS.Next();
            }

            return(null);

            // Alternative approach is to use the dataset extension

            /*
             * // Get extension container
             * IFeatureDatasetExtensionContainer fdce = (IFeatureDatasetExtensionContainer)fd;
             *
             * // Find UN dataset by type
             * IFeatureDatasetExtension unFDSExt = fdce.FindExtension(esriDatasetType.esriDTUtilityNetwork);
             * IDatasetContainer2 unDSContainer = (IDatasetContainer2)unFDSExt;
             *
             * IEnumDatasetName dsNames = unDSContainer.DatasetNames[esriDatasetType.esriDTUtilityNetwork];
             *
             * IDatasetName dsName = dsNames.Next();
             * if (dsName != null)
             * {
             *  unDataset = unDSContainer.DatasetByName[esriDatasetType.esriDTUtilityNetwork, dsName.Name];
             * }
             */
        }
        public IDataset GetUNDataset2(IServerObject serverObject, string versionName = null)
        {
            IDataset             unDataset           = null;
            IMapServer           mapService          = (MapServer)serverObject;
            IMapServerDataAccess mapServerDataAccess = (IMapServerDataAccess)serverObject;

            // Get feature class from any layer
            IFeatureClass fc = (IFeatureClass)mapServerDataAccess.GetDataSource(mapService.DefaultMapName, 0);

            // Get the container feature dataset
            IFeatureDataset fd = fc.FeatureDataset;

            // Open feature dataset in specified version
            if (!String.IsNullOrEmpty(versionName))
            {
                IWorkspace           workspace          = fd.Workspace;
                IVersionedWorkspace4 versionedWorkspace = (IVersionedWorkspace4)workspace;
                IVersion4            childVersion       = (IVersion4)versionedWorkspace.FindVersion(versionName);
                IFeatureWorkspace    childFWS           = (IFeatureWorkspace)childVersion;
                fd = childFWS.OpenFeatureDataset(fd.Name);
            }

            // Get extension container
            IFeatureDatasetExtensionContainer fdce = (IFeatureDatasetExtensionContainer)fd;

            // Find UN dataset by type
            IFeatureDatasetExtension unFDSExt      = fdce.FindExtension(esriDatasetType.esriDTUtilityNetwork);
            IDatasetContainer2       unDSContainer = (IDatasetContainer2)unFDSExt;

            IEnumDatasetName dsNames = unDSContainer.DatasetNames[esriDatasetType.esriDTUtilityNetwork];

            IDatasetName dsName = dsNames.Next();

            if (dsName != null)
            {
                unDataset = unDSContainer.DatasetByName[esriDatasetType.esriDTUtilityNetwork, dsName.Name];
            }

            return(unDataset);
        }