How To Get All Features in FeatureClass with ArcObjects

How to publish a ArcMap to the ArcGIS Server…

4. August 2010 10:02 by Scott in   //  Tags:   //   Comments (46)

So after tons of searching and bothersome problems, It took a while to find code, but none could be found.  So I wanted to make sure the end example was easily findable on the internet next time.  Hope this saves some time of another programmer out there!

This code will publish an .MXD map to the ArcGIS server.  And turn it on to be used right away.

 //The following C# code shows how to connect to the ArcGIS Server called "     ",
        //and use the IServerObjectConfiguration interface to set the properties of
        //a new server object configuration. The new configuration is created and
        // added to the server with the 
        //CreateConfiguration and AddConfiguration methods on IServerObjectAdmin.
        /// <summary>
        /// This publishes a Map to the ArcGIS Server
        /// </summary>
        /// <param name="serverMachineName">Servername</param>
        /// <param name="serviceName">Service name in which you want to call it</param>
        /// <param name="pathToMap">File Path to the .mxd map.</param>
        /// <param name="format">Which format you would like.  Look in code.</param>
        public static void AddMapService(string serverMachineName, string serviceName, string pathToMap, int format)
        {
            // Initialize ESRI licenses
            IAoInitialize aoInit = new AoInitializeClass();
            aoInit.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcServer);

            //define paths for the onlineresource property in the extension properties
            string resource = "http://" + serverMachineName + "/ArcGIS/services/" + serviceName + "/MapServer/WMSServer";
            string resourceKML = "http://" + serverMachineName + "/ArcGIS/services/" + serviceName + "/MapServer/KMLServer";
            string resourceWCS = "http://" + serverMachineName + "/ArcGIS/services/" + serviceName + "/MapServer/WCSServer";
            string resourceWFS = "http://" + serverMachineName + "/ArcGIS/services/" + serviceName + "/MapServer/WFSServer";

            //  Connect to the ArcGIS server called  serverMachineName (string) .   
            IGISServerConnection pGISServerConnection = new GISServerConnectionClass();
            // example :  pGISServerConnection.Connect("llv38-tasc65688");   
            pGISServerConnection.Connect(serverMachineName);

            // create the new configuration
            IServerObjectAdmin pServerObjectAdmin = pGISServerConnection.ServerObjectAdmin;
            IServerObjectConfiguration pConfiguration = pServerObjectAdmin.CreateConfiguration();
            IServerObjectConfiguration2 pConfiguration2 = (IServerObjectConfiguration2)pConfiguration;
            IServerObjectConfiguration3 pConfiguration3 = (IServerObjectConfiguration3)pConfiguration;

            // set the   General Configuration Settings
            pConfiguration.Name = serviceName;           //  the name of this configuration
            pConfiguration.TypeName = "MapServer";   // the type of server object to be created
            pConfiguration.IsPooled = true;
            pConfiguration.MinInstances = 1;
            pConfiguration.MaxInstances = 2;
            pConfiguration.WaitTimeout = 60;
            pConfiguration.UsageTimeout = 600;
            pConfiguration.StartupType = esriStartupType.esriSTAutomatic;
            pConfiguration.IsolationLevel = esriServerIsolationLevel.esriServerIsolationHigh;

            //  Set the configuration Properties of the MapServer Object
            IPropertySet pProps = pConfiguration.Properties;
            pProps.SetProperty("FilePath", pathToMap);    // required property
            pProps.SetProperty("OutputDir", "c:\\arcgisserver\\arcgisoutput");
            string virtualOutDir = " http://" + serverMachineName + "/arcgisoutput";
            pProps.SetProperty("VirtualOutputDir", virtualOutDir);
            pProps.SetProperty("MaxImageHeight", "2048");
            pProps.SetProperty("MaxRecordCount", "500");
            pProps.SetProperty("MaxBufferCount", "100");
            pProps.SetProperty("MaxImageWidth", "2048");
            pConfiguration.Properties = pProps;

            //  Set the info segment of the MapServer Object  properties
            IPropertySet info = pConfiguration2.Info;
            info.SetProperty("WebEnabled", "true");
            info.SetProperty("WebCapabilities", "Map,Query,Data");
            pConfiguration2.Info = info;

            //  Set the recycle properties of the MapSrver object
            IPropertySet pProp = pConfiguration.RecycleProperties;
            pProp.SetProperty("StartTime", "1:00 AM");    //   start recycling at midnight
            pProp.SetProperty("Interval", "86400");      //  every 24 hours
            pConfiguration.RecycleProperties = pProp;

            bool enabled;
            if (format == 1 || format == 15)
            {   //Set WMS extension Properties
                pConfiguration2.set_ExtensionEnabled("WmsServer", true);

                IPropertySet pExtensionProps = pConfiguration2.get_ExtensionProperties("WmsServer");
                pExtensionProps.SetProperty("OnlineResource", resource);
                pExtensionProps.SetProperty("Name", "WMS");
                pExtensionProps.SetProperty("Title", serviceName);
                // pConfiguration2.set_ExtensionProperties("WmsServer", pExtensionProps);

                IPropertySet pProp2 = pConfiguration2.get_ExtensionInfo("WmsServer");
                pProp2.SetProperty("WebEnabled", "true");
                pProp2.SetProperty("WebCapabilities", "Map,Query,Data");
                pConfiguration2.set_ExtensionInfo("WmsServer", pProp2);
            }

            if (format == 2 || format == 15)
            {    //  Set KML extension properties
                pConfiguration2.set_ExtensionEnabled("KMLServer", true);

                IPropertySet pPropKML = pConfiguration2.get_ExtensionInfo("KMLServer");
                pPropKML.SetProperty("WebEnabled", "true");
                pPropKML.SetProperty("WebCapabilities", "SingleImage,SeparateImages,Vectors");
                pConfiguration2.set_ExtensionInfo("KMLServer", pPropKML);

                IPropertySet pExtensionPropKML = pConfiguration2.get_ExtensionProperties("KMLServer");
                pExtensionPropKML.SetProperty("ImageSize", "1024");
                pExtensionPropKML.SetProperty("FeatureLimit", "1000000");
                pExtensionPropKML.SetProperty("Dpi", "96");

                pExtensionPropKML.SetProperty("MinRefreshPeriod", "30");
                pExtensionPropKML.SetProperty("UseDefaultSnippets", "false");
                //       pConfiguration2.set_ExtensionProperties("KMLServer", pExtensionPropKML);
            }

            if (format == 4 || format == 15)
            {   //Set WCS extension Properties
                pConfiguration2.set_ExtensionEnabled("WcsServer", true);

                IPropertySet pExtensionPropsWCS = pConfiguration2.get_ExtensionProperties("WcsServer");
                pExtensionPropsWCS.SetProperty("OnlineResource", resourceWCS);
                pExtensionPropsWCS.SetProperty("Name", "WCS");
                pExtensionPropsWCS.SetProperty("Title", serviceName);
                // pConfiguration2.set_ExtensionProperties("WcsServer", pExtensionPropsWCS);

                IPropertySet pPropWCS = pConfiguration2.get_ExtensionInfo("WcsServer");
                pPropWCS.SetProperty("WebEnabled", "true");
                pConfiguration2.set_ExtensionInfo("WcsServer", pPropWCS);
            }


            if (format == 8 || format == 15)
            {   //Set WFS Extension Properties
                pConfiguration2.set_ExtensionEnabled("WfsServer", true);

                IPropertySet pExtensionPropsWFS = pConfiguration2.get_ExtensionProperties("WfsServer");
                pExtensionPropsWFS.SetProperty("OnlineResource", resourceWFS);
                pExtensionPropsWFS.SetProperty("Name", "WFS");
                pExtensionPropsWFS.SetProperty("Title", serviceName);
                pExtensionPropsWFS.SetProperty("AppSchemaURI", resourceWFS);
                pExtensionPropsWFS.SetProperty("AppSchemaPrefix", serviceName);
                //     pConfiguration2.set_ExtensionProperties("WfsServer", pExtensionPropsWFS);

                IPropertySet pPropWFS = pConfiguration2.get_ExtensionInfo("WfsServer");
                pPropWFS.SetProperty("WebEnabled", "true");
                pConfiguration2.set_ExtensionInfo("WfsServer", pPropWFS);
            }

            //' add the configuration to  the server
            pServerObjectAdmin.AddConfiguration(pConfiguration2);
            pServerObjectAdmin.StartConfiguration(serviceName, "MapServer");
        }  //  end method
If you liked this post, please be sure to subscribe to my RSS Feed.

Comments (46) -

Martinez
Martinez
4/28/2011 7:38:33 AM #

Thanks a lot for the post. This is exactly what I need. Hope it worksSmile (gonna try soon)

how to hack twitter
how to hack twitter
6/8/2013 1:12:05 PM #

If you cant gain access to your account, then use the hyperlink above. com with a Twitter update that read: "TANGO DOWN -  - for being terrorist scum. In return, further measures will be taken to solve game design problems wherever needed.

Check out my site;  how to hack twitter - http://howtohacktwitteraccount.com

itunes gift card generator
itunes gift card generator
6/8/2013 2:29:39 PM #

These vouchers will give you a fantastic genre of new music that will keep you posted on the most recent albums and hits of your favorite singer. If you find it hard to decide on which number sets and combination to go for and bet with on the lottery, maybe free lottery number generator software can help you with that. As extended as they have the most recent model of i - Tunes and world wide web entry, then they will be capable to redeem their current card in return for entry to the i - Tunes keep.

my website  itunes gift card generator - http://www.youtube.com/watch?v=5gAUW-b5bjE

top espresso machines
top espresso machines
6/18/2013 1:47:37 AM #

Thank you for sharing your excellent web-site.

my weblog;  top espresso machines - http://espressomachinesreviews2013.info

discount metal detectors
discount metal detectors
6/24/2013 8:30:23 PM #

Hi there, very good website you've at this time there.

Look into my page:  discount metal detectors - http://bestmetaldetector2013.info

table saw reviews
table saw reviews
6/27/2013 8:00:42 PM #

Wow, gorgeous site. Thnx ...

Review my site  table saw reviews - http://www.besttablesawsreviews.org/

waterproof metal detector
waterproof metal detector
6/28/2013 1:33:33 AM #

Good webpage you've right here.

Feel free to surf to my weblog  waterproof metal detector - http://metaldetectorreviews2013.info

metal detectors for gold
metal detectors for gold
7/1/2013 1:23:01 AM #

You have among the best websites.

My homepage  metal detectors for gold - http://topmetaldetectorsreviews.info

减肥药排行榜
减肥药排行榜
7/12/2013 3:25:32 AM #

Hey! Do you use Twitter? I'd like to follow you if that would be okay. I'm undoubtedly enjoying your blog and look forward to new updates.

Also visit my webpage:  减肥药排行榜 - http://www.xianzaijianfei.com/

duplicate finder reviews
duplicate finder reviews
7/13/2013 11:57:32 PM #

Do you mind if I quote a couple of your articles as long as I provide credit and sources back to your webpage? My website is in the very same area of interest as yours and my users would genuinely benefit from some of the information you present here. Please let me know if this ok with you. Cheers!

Check out my webpage ::  duplicate finder reviews - www.ashisoft.com/duplicate-file-finder-review.htm

Remove Duplicate Files
Remove Duplicate Files
7/14/2013 9:04:36 AM #

Right here is the perfect website for anyone who would like to find out about this topic. You understand a whole lot its almost tough to argue with you (not that I really would want to…HaHa). You certainly put a new spin on a subject that has been written about for decades. Wonderful stuff, just great!

My website:  Remove Duplicate Files - http://www.duplicate-finder.net

tirage tarot gratuit
tirage tarot gratuit
7/21/2013 8:48:57 AM #

Astrologie balance homme sex vies anterieures test

my web site;  tirage tarot gratuit - http://www.urocomp.org

tarot gratuit
tarot gratuit
7/25/2013 1:50:45 AM #

Horoscope balance gratuit 2012 milfs  calculer mon signe astrologique

Take a look at my homepage ::  tarot gratuit - http://www.bartlatjes.com

link building packages
link building packages
8/3/2013 3:45:35 PM #

Howdy would you mind sharing which blog platform you're using? I'm planning to start my own blog in the near future but I'm having a hard time selecting between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design seems different then most blogs and I'm looking for something unique.                  P.S Sorry for getting off-topic but I had to ask!

Feel free to surf to my page ...  link building packages - http://blog-makrame.ru/?p=18

internet marketing lead generation
internet marketing lead generation
8/5/2013 8:11:10 AM #

Your style is so unique compared to other people I've read stuff from. I appreciate you for posting when you have the opportunity, Guess I will just bookmark this blog.

Visit my page;  internet marketing lead generation - 157.82.81.13/.../...d_Generation_Net_Web_site.html

voyance par telephone
voyance par telephone
8/5/2013 10:10:36 AM #

Site d astrologie medium gratuite en ligne

my web blog -  voyance par telephone - http://www.voyantpartelephone.org

Vicky
Vicky
8/8/2013 7:09:23 AM #

I'm extremely pleased to uncover this website. I want to to thank you for your time for this wonderful read!! I definitely savored every bit of it and i also have you book marked to see new stuff in your web site.

Feel free to surf to my page washington credit [ Vicky - http://shortairport7203.newsvine.com ]

Brittany
Brittany
8/8/2013 8:23:21 AM #

If some one wishes expert view concerning running a blog then i propose him/her to go to see this web site, Keep up the pleasant work.

Here is my webpage ... crm business solutions ( Brittany - www.ranker.com/profile-of/cataloguesnocreditcheck )

lottery results raffle
lottery results raffle
8/9/2013 10:03:33 PM #

Hello i am kavin, its my first occasion to commenting anywhere, when i read this piece of writing i thought i could also make comment due to this good  paragraph.

my web-site:  lottery results raffle - http://fftupload.com/user/143463/DeboraWhi

SKF Bearing
SKF Bearing
8/10/2013 11:24:27 AM #

7% of the imported bearings, such as skf, nsk, and timken bearings. To reduce the rotational friction and improve the speed levels,. Properly, among all the different products, NSK bearings are quite famous.

Feel free to surf to my homepage -  SKF Bearing - Rvline.ru/.../Standards_For_Root_Factors_For_skf_bearings

value my car for free
value my car for free
8/10/2013 4:18:38 PM #

Just desire to say your article is as astounding. The clearness for your publish is simply nice and i can assume you're knowledgeable in this subject. Well along with your permission let me to seize your RSS feed to stay up to date with impending post. Thanks 1,000,000 and please keep up the gratifying work.

My site;  value my car for free - www.sitemembershipscript.com/.../index.php

penis lengthening
penis lengthening
8/12/2013 7:53:04 PM #

bookmarked!!, I really like your site!

Also visit my homepage  penis lengthening - http://mrso-Mon.ru/node/69968

prices of second hand cars
prices of second hand cars
8/13/2013 6:08:02 AM #

Hey there would you mind sharing which blog platform you're working with? I'm going to start my own blog soon but I'm having a hard time deciding between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design and style seems different then most blogs and I'm looking for something completely unique.                  P.S Apologies for getting off-topic but I had to ask!

Also visit my webpage:  prices of second hand cars - http://www.second-hand-car.com/sell-your-car.php

what is a good used car to buy
what is a good used car to buy
8/13/2013 5:54:27 PM #

Thank you a bunch for sharing this with all people you actually know what you're talking approximately! Bookmarked. Please additionally discuss with my web site =). We will have a hyperlink alternate contract between us

my website:  what is a good used car to buy - highversation.bradenleeblack.com/.../

stress and panic attacks
stress and panic attacks
8/14/2013 4:36:03 AM #

Pour much liquid while you need at the tank toward the rear (retaining planned you can prepare the maximum of 10 cups of coffee), invest the filter (otherwise 2, when they are really thin filter systems) containing ground coffee at the filter basket above the pot. These kinds of coffee makers, although these are typically less familiar, provide something a variety of for coffee fans, regardless through the sheer assortment of coffee types and additionally flavors available for pod machines, or even the past times planet tastes developed.

Also visit my web-site;  stress and panic attacks - gserver.sampos.ch/wiki/index.php?title=Benutzer:GaryMagan

normal Penis Size
normal Penis Size
8/14/2013 10:53:54 AM #

Tremendous issues here. I am very satisfied to look your article. Thank you so much and I'm looking forward to contact you. Will you please drop me a e-mail?

my weblog ::  normal Penis Size - www.articlecube.com/profile/Emile-Griswold/433159

penis Enhancement plastic surgery
penis Enhancement plastic surgery
8/14/2013 3:33:32 PM #

Nicely put, Appreciate it!

My homepage ...  penis Enhancement plastic surgery - http://clickforu.com/profile-275490/info/

normal penis
normal penis
8/15/2013 5:38:35 PM #

Do you have any video of that? I'd like to find out some additional information.

Also visit my webpage:  normal penis - www.hanurikorean.com/zbxe/?document_srl=103951

medium gratuit
medium gratuit
8/16/2013 10:39:42 PM #

Tarot famille voyance tirage tarot gratuit

my webpage:  medium gratuit - http://www.monvoyant.org

Microsoft Office 2007
Microsoft Office 2007
8/17/2013 2:46:46 AM #

With havin so much written content do you ever run into any problems of plagorism or copyright infringement? My site has a lot of exclusive content I've either created myself or outsourced but it looks like a lot of it is popping it up all over the internet without my authorization. Do you know any ways to help prevent content from being stolen? I'd truly appreciate it.

Take a look at my web site  Microsoft Office 2007 - http://officeitsolution.com/

Latricia
Latricia
8/18/2013 2:37:45 AM #

Good respond in return of this query with solid arguments and describing all on the topic of that.
Latricia - http://www.coolwebsite3288c.com

Take a look at my page ...  Latricia - http://www.coolwebsite328c.com

tablette graphique
tablette graphique
8/18/2013 5:42:11 PM #

Everything is very open with a precise explanation of the challenges. It was definitely informative. Your website is extremely helpful. Thank you for sharing!

Also visit my page -  tablette graphique - http://www.tablettegraphique123.net/

penis size
penis size
8/18/2013 9:32:24 PM #

Nice post. I learn something totally new and challenging on blogs I stumbleupon every day. It's always exciting to read through content from other writers and use a little something from other sites.

my website  penis size - themostcake.co.uk/.../

max credit
max credit
8/19/2013 6:51:47 AM #

Its like you read my mind! You appear to know a lot about this, like you wrote the book in it or something. I think that you can do with some pics to drive the message home a little bit, but other than that, this is fantastic blog. A great read. I'll definitely be back.

My weblog ::  max credit - http://sgpersonalloan.com

medium
medium
8/20/2013 10:40:06 AM #

Voyance gratite verseau astrologie compatibilite

my website ::  medium - http://www.agiftforthefuture.org

trade in value of A car
trade in value of A car
8/20/2013 5:26:15 PM #

This is the right blog for anyone who wants to find out about this topic. You realize so much its almost hard to argue with you (not that I personally will need to…HaHa). You definitely put a brand new spin on a subject that's been written about for decades. Excellent stuff, just excellent!

Also visit my web site;  trade in value of A car - http://jaeil.piahosting.net/?document_srl=58007

medium gratuit
medium gratuit
8/20/2013 7:04:26 PM #

Horoscope chinois cochon jour signe astrologique calcul

Feel free to visit my website ::  medium gratuit - http://www.moeys-elibrary.org

http://lungenforum.jjays.info/wiki/index.php?title=The_Burden_of_Being_the_Starting_Born
http://lungenforum.jjays.info/wiki/index.php?title=The_Burden_of_Being_the_Starting_Born
8/21/2013 12:55:48 PM #

In the event the objects aren't used usually you can move it in return to once every single 2 or 3 months, however always tend to be doing it frequently sufficient that the scale establish isn't as of yet visable whenever your clean up the product. you may find around this a partners of methods firstly you will find the choice to dilute the espresso alongside drinking water or next if at all like me you see coffee just a tiny bit too strong you may create it the Spanish method.

Feel free to visit my web page: panic and depression ( lungenforum.jjays.info/.../index.php - lungenforum.jjays.info/.../index.php )

check vehicle history
check vehicle history
8/21/2013 5:04:05 PM #

What's up i am kavin, its my first time to commenting anyplace, when i read this post i thought i could also create comment due to this good  paragraph.

Also visit my homepage;  check vehicle history - japavtube.com/.../...-owner-on-deal-autos-908.html

penis enlargement techniques
penis enlargement techniques
8/22/2013 3:47:58 AM #

Amazing material, Thank you!

My web-site ...  penis enlargement techniques - moodle.cephuelva.org/.../view.php

voyance gratuite
voyance gratuite
8/22/2013 5:02:34 PM #

Daily horoscope scorpio tarot divinatoire gratui

My web site:  voyance gratuite - http://www.natashasfoodforpaws.com

max credit
max credit
8/23/2013 2:23:56 AM #

Hi friends, how is everything, and what you want to say about this article, in my view its truly awesome for me.

Feel free to surf to my page ...  max credit - http://ezfastcashpersonalloans.com

films porno
films porno
8/23/2013 2:55:19 AM #

Transsexuel amateur video chatte amateur

my blog post:  films porno - http://www.filmpornoxgratuit.com

retweet09.ru
retweet09.ru
8/23/2013 9:52:49 AM #

Greetings! This is my first comment here so I just wanted to give a quick shout out and say I truly enjoy reading your posts. Can you recommend any other blogs/websites/forums that cover the same subjects? Thanks a lot!

Review my blog ... car insurance premium calculator ( retweet09.ru - retweet09.ru/.../ )

what makes a dog have diarrhea
what makes a dog have diarrhea
8/23/2013 10:10:47 PM #

Greetings! Very helpful advice within this article! It's the little changes that produce the most important changes. Thanks for sharing!

Here is my web site;  what makes a dog have diarrhea - samariterteam.ch/.../view.php

personal loan
personal loan
8/24/2013 11:00:36 AM #

I am now not certain the place you are getting your info, but good topic. I must spend some time studying much more or understanding more. Thanks for magnificent information I used to be searching for this information for my mission.

my blog ...  personal loan - http://www.monetiumcredit.com.sg