Вы находитесь на странице: 1из 2

Public Shared Sub CreateMyMapServiceInArcGISServer( _

ByVal MyServerName As String, _

ByVal MyServiceName As String, _
ByVal pIsPooled As Boolean, _
ByVal MyMXDFilePath As String)

‘...This subroutine is used to create MapService in ArcGIS Server

‘...by passing the required parameters from main program
‘...This subroutine can be put in a Class or a Module in a Web Application
‘...For detailed information about the ArcObjects, please visit ESRI EDN
‘...pServerName = the Server name
‘...pServiceName = the name of Map Service will be created
‘...pIsPooled = either True (pooled) or False (non-pooled)
‘... depending on the purpose of the map serivce
‘...MyMXDFilePath = the file path of the MXD that will be used for Map Service
'... Using ArcGIS Server API (ArcObjects)
Dim Mygisconnection As New ESRI.ArcGIS.Server.GISServerConnectionClass()

'...ArcGIS Server manager

Dim serverManager As IServerObjectManager
serverManager = Mygisconnection.ServerObjectManager

'...Connect to ServerObjectManager
Dim pServerObjectManager As ESRI.ArcGIS.Server.IServerObjectManager
pServerObjectManager = Mygisconnection.ServerObjectManager

'...Sing in ServerObjectAdministrator
Dim pServerObjectAdmin As ESRI.ArcGIS.Server.IServerObjectAdmin
pServerObjectAdmin = Mygisconnection.ServerObjectAdmin

' Create the new configuration.

Dim pConfiguration As ESRI.ArcGIS.Server.ServerObjectConfiguration
pConfiguration = pServerObjectAdmin.CreateConfiguration()

'...Assign the name of "MapService" and other configurations

With pConfiguration
.Name = MyServiceName
.TypeName = "MapServer"
.IsPooled = pIsPooled
.MinInstances = 1
.MaxInstances = 10
.WaitTimeout = 10
.UsageTimeout = 120
.Description = "Map Description"
End With

‘... Since it is a web application so replace the path with the server name
Dim path As String = MyMXDFilePath
path = path.Replace("C:", "\\" + pServerName)

'... put the physical location of MXD into pProps

Dim pProps As ESRI.ArcGIS.esriSystem.IPropertySet = pConfiguration.Properties
pProps.SetProperty("FilePath", path)

'...Enum all the configurations in Server Objects

Dim pEnumConfigInfo As ESRI.ArcGIS.Server.IEnumServerObjectConfigurationInfo
pEnumConfigInfo = pServerObjectManager.GetConfigurationInfos

'...Looping all the Configures (Map Services)

Dim pConfigInfo As ESRI.ArcGIS.Server.IServerObjectConfigurationInfo
pConfigInfo = pEnumConfigInfo.Next

Dim pExist As Boolean = False

Do Until pConfigInfo Is Nothing

'...if the MapService exists, exit do
If UCase(pConfigInfo.Name) = temp_ServiceName.ToUpper Then
pExist = True
Exit Do
End If
pConfigInfo = pEnumConfigInfo.Next()

'... if the map serivce is not found, add the MapService to the server.
If pExist = False Then
pServerObjectAdmin.StartConfiguration(pConfiguration.Name, _
MsgBox("Please set the folder to be shared or unable to create a map service")
End Try
End If

'...Release memory
Mygisconnection = Nothing
pServerObjectManager = Nothing
pServerObjectAdmin = Nothing
pProps = Nothing
pEnumConfigInfo = Nothing
pConfigInfo = Nothing
pConfiguration = Nothing

End Sub

Note: This VB (6 or .Net) sample code and/or comments contained herein are provided “as is” without any warranty. The site-
www.shapefile.us shall not be liable for direct, indirect, special, incidental, or consequential damages related to any decisions you
make by using any of the information and/or materials listed and/or posted on this page.