Get info from a MSD based map service?

Discussion created by gilest on Jul 2, 2010
working w/ ArcGIS 9.3.1, writing VBA in ArCatalog..

I'm using the following code to get the the underlying Map object for a bunch of map services -
Sub LoopAGSservices()

    'variables for the ArcCat application, view, and Selecteced objects, and a single object
    Dim pGxApp As IGxApplication
    Dim pGXEnum As IEnumGxObject
    Dim pGxObj As IGxObject
    Set pGxApp = Application
    Dim pgcat As IGxCatalog
    'make sure at least one server selected
    If pGxApp.Selection.count < 1 Then
      MsgBox "Please select at least 1 GIS Server in the Contents Tab.", , "No Server selected."
      pGxApp.Selection.Clear pGxApp
      Exit Sub
    End If
    'get Enumerator of selected objects and loop through it
    Set pGXEnum = pGxApp.Selection.SelectedObjects
    Set pGxObj = pGXEnum.Next

    Dim intServer As Integer
    Dim intService As Integer

    'server, som, server context (serivce), map service
    Dim pSrvConn As IGISServerConnection
    Dim pSOM As IServerObjectManager
    Dim pSOAdmin As IServerObjectAdmin4

    Dim pEnumSOC As IEnumServerObjectConfiguration
    Dim pSOC As IServerObjectConfiguration
    Dim pServerContext As IServerContext
    Dim pServerObject As IServerObject
    Dim pMapServer As IMapServer2
    Dim strMXD As String

    Do While Not pGxObj Is Nothing

      If TypeOf pGxObj Is GISServerConnection Then
        intServer = intServer + 1
        intService = 0
        Set pSrvConn = New GISServerConnection
        pSrvConn.Connect Left(pGxObj.Name, InStr(pGxObj.Name, " ") - 1) 'drop the "(admin)" from connection name
        Set pSOM = pSrvConn.ServerObjectManager
        Set pSOAdmin = pSrvConn.ServerObjectAdmin
        Set pEnumSOC = pSrvConn.ServerObjectAdmin.GetConfigurations
        Set pSOC = pEnumSOC.Next
        Do Until pSOC Is Nothing
          intService = intService + 1
          strMXD = ""
          If pSOC.TypeName = "MapServer" Then

            If pSOAdmin.GetConfigurationStatus(pSOC.Name, "MapServer").Status = esriCSStarted Then

              Set pServerContext = pSOM.CreateServerContext(pSOC.Name, "MapServer")
              Set pServerObject = pServerContext.ServerObject
              Set pMapServer = pServerObject
              strMXD = pSOC.Properties.GetProperty("FilePath")
              If strMXD <> "" Then
                GetMapInfoforService pServerObject.ConfigurationName & ";" & pMapServer.DocumentInfo.GetProperty("author"), strMXD, "d:\temp\mapservices.txt"
              End If
              Debug.Print pSOC.Name & " is not started"
            End If
          End If
          Set pSOC = pEnumSOC.Next

      End If
      Set pGxObj = pGXEnum.Next

End Sub

Sub GetMapInfoforService(strService As String, strFile As String, strWriteFile As String)

  On Error GoTo EH
  'test to see if valid MXD
  Dim pMapDoc As IMapDocument
  Set pMapDoc = New MapDocument
  If Not pMapDoc.IsMapDocument(strFile) Then
    Open strWriteFile For Append As #1
      Print #1, strFile & ";Cannot open MXD - appears to be corrupt"
    Close #1
    Exit Sub
  End If
  'Open the MapDoc & it's Map Collection and loop thru it
  pMapDoc.Open strFile
  Dim intX As Integer
  Dim pmap As IMap
  For intX = 0 To pMapDoc.MapCount - 1
    Set pmap = pMapDoc.Map(intX)
    'run layer & table documentor
    Map_Info pmap, strFile, strWriteFile
  Exit Sub
  Debug.Print "error in GetMapInfo " & Err.Description
End Sub

which works great when the map service is based on a MXD file.  However I'm stuck when it comes to optimized map services and the associated MSD file - are there any classes & interfaces that I can use to get the name of the MXD it was created from? 

If there's .Net way to do it, I'm open to that too!