Create MSD in 10.2

4270
4
06-27-2014 04:07 PM
DerivenC
New Contributor II
Background:
In 10.0, I'm able to create a map service in less than 2 seconds with ArcObjects.NET.  My software has clients all over the US that got very used to new map services up within 10 seconds.  They are able to receive new analysis layers quickly.

Problem:
With 10.1 and now 10.2, the ability to create a map service has been taken away from ArcObjects.NET (in a matter of speaking).  I have to use ArcPy and/or REST API.  I'd be fine with that.  But it now takes 25-35 seconds to create a map service.  8 seconds of that is the initialization of Python.  The rest comes from setting up the SD draft, then to stage SD, then to publish.

What I've noticed is that 10.2 still uses MSD files.  And the REST API can create a service with the right service description, which needs an MSD file.  So if I could create an MSD file from my MXD and make one REST call, that would be considerably faster.

But .. the MSDHelper class in ArcObjects doesn't want to work.  I can instantiate it.  But when I attempt to use the Open method, it fails every time.  Regardless of license initialization.  The error received is:

Exception from HRESULT: 0x80040353
ESRI.ArcGIS.Carto
   at ESRI.ArcGIS.Carto.MSDHelperClass.Open(String Path)
   at ArcGisLab.Program.Main(String[] args) in c:\Projects\Lab\ArcGisLab\Program.cs:line 32
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

The MXD file exists and has been published successfully with ArcPy.

Question:
Is MSDHelper deprecated?  If not, how can I use it?  Or how can I create an MSD file in ArcObjects.NET?  I do NOT want to call Python within .NET.
0 Kudos
4 Replies
DerivenC
New Contributor II
For every Python script I run that requires arcpy, there is a 4 second initialization.  This is what's killing me the most.

I can get rid of that 4 * n seconds if I run Python in interactive mode (wrapped in a Process object) and import arcpy and other Python libraries at the start .. then feed script text.

That's really annoying.  But I guess it'll have to do.

Sure wish I could do a lot more with ArcObjects like I could in 10.0...
0 Kudos
ErinBrimhall
Occasional Contributor II
I ran into this problem as well after upgrading to Arc 10.1.

The ability to create or otherwise administer services with ArcObjects was effectively lost when the ability to make "local connections" to ArcGIS Server was removed.  Like you, I also found that Python was the only option for automating the creation of Map Services, and that the time it takes to do so is considerably longer than with ArcObjects.

One quick note regarding MSDHelper and its Open method: I believe this is intended to open an existing .msd file, not a map document (MXD).  It is odd that ArcGIS Server is still using MSD files even though the documentation says they've been replaced with SDs:

Starting at ArcGIS 10.1 for Server, Map Server Definition (.msd) files have been replaced with Service Definition Draft (.sddraft) and Service Definition (.sd) files. Please use the CreateMapSDDraft function instead.


You can treat SD and MSD files as zip-archives and take a peek at the internal structure.  I imagine it'd be possible to establish an SD "template" file and use it as a starting point for creating new services.  This would save you from the hassle of invoking the time-consuming Python methods for creating SDDRAFT and SD files on the fly, but I'm not sure all the added complexity would be worth it.
0 Kudos
DerivenC
New Contributor II
good stuff


I cannot thank you enough for the info, Erin!  I knew that the MPK files were ZIP but it didn't occur to me that MSD and SD files were.  Just like Office 2007 files, I can unzip them, update them, and rezip them up.

You are right about the MSDHelper.  I saw someone else's code on the net and tried it, not looking at the signature of the Open method.  Should've done my homework.

Anyway, now I don't have to fall back to a hybrid 10.0 Server/10.2 Desktop solution to get the best of both worlds.
0 Kudos
DerivenC
New Contributor II
Upon reviewing the metadata, I agree that it would be too cumbersome to attempt.  Would be useful for a copy/paste of like-minded map services/layers.  But overall, far too risky and costly to develop.

I'm back to my ArcGIS Server 10.0/Desktop 10.2.2 hybrid.  And that's fine I guess.
0 Kudos