Vb.Net or C# code to Connect to ArcGIS Server 10.2

3475
8
02-04-2016 01:28 PM
JoseSanchez
Occasional Contributor III

Hello everyone,

Anyone can share a source code in C# or VB.Net about how to connect to ArcGIs Server.

I have a code that was working in 10.0 but it does not work anymore.

Thank you.

8 Replies
ChrisSmith7
Frequent Contributor

Are you looking to interface with server through the web or through runtime SDK?

0 Kudos
JoseSanchez
Occasional Contributor III

Runtime SDK.

0 Kudos
ChrisSmith7
Frequent Contributor

Can you be more specific as to what you're trying to do? For instance, this page - Use a MapView to display a map—ArcGIS Runtime SDK for .NET | ArcGIS for Developers  - describes how to display a map using the runtime SDK. If you notice, there are service URIs for tiled map services and also feature layers, e.g. http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Earthquakes/EarthquakesFromLastSevenDays/..."/

That's a connection to ArcGIS Server...

0 Kudos
RebeccaStrauch__GISP
MVP Esteemed Contributor

I can't answer your question...but tagging ArcGIS Runtime SDK for .NET  for more exposure.

0 Kudos
ScottMason
New Contributor II

I believe you have to do it through map services.  After searching for a long time I found this

Supported geodatabase formats—ArcGIS Runtime SDK for .NET | ArcGIS for Developers

which says

ArcGIS Runtime for .NET against Enterprise geodatabase -> Supported only if using services

I hope someone proves me wrong.

0 Kudos
KrisFoster
New Contributor III

Hi Jose,

Depends on what you mean by connect I suppose.  I put two samples below that should work.  Once simply adding the ArcGIS Server layer to a current map view, and another querying against an ArcGIS Server layer.

//Add a new dynamic map service layer.  Replace the URL with your desired ArcGIS Server rest URL.

//Use ArcGISTiledMapServiceLayer if it is a tile map service instead.

var layer = new ArcGISDynamicMapServiceLayer(new Uri("http://MyServer/arcgis/rest/services/MyService/MapServer"));

await layer.InitializeAsync();

//add the layer to the map and zoom to its extent

this.MyMapView.Map.Layers.Add(layer);

If by connect you mean you just want to query against the layer, then you'll want to use a QueryTask.

QueryTask myQueryTask = new QueryTask(new Uri("http://MyServer/arcgis/rest/services/MyService/MapServer/0"));

Query myQuery = new Query("OBJECTID < 100");

OrderByField myOrder = new OrderByField("OBJECTID", SortOrder.Ascending);

myQuery.OrderByFields.Add(myOrder);

myQuery.ReturnGeometry = true;

myQuery.OutFields.Add("OBJECTID");

myQuery.OutFields.Add("GLOBALID");

QueryResult myResult = await myQueryTask.ExecuteAsync(myQuery);

0 Kudos
MichaelRobb
Regular Contributor II

from 10.0 to 10.1 there was a huge change on how to access ArcGIS Server...  Local connections (AGSConnection())  are no more... I am sure you have found that out.

As per others questions, it depends on what you are looking for.

It is through the REST/SOAP service API?

Is it to create SOIs or SOEs ? ( Server object interceptors / Server object extensions )

0 Kudos
JoseSanchez
Occasional Contributor III

Hello everyone,

I just want to re-write this VB.Net code using ArcGIS Server 10.2. It works fine in ArcGIS Server 10.0 but it fails in ArcGIS Server 10.2:

Dim gputilities As IGPUtilities = New GPUtilitiesClass()

        Dim myResult As Boolean = True

        ' Declare server context variables
        Dim mapServerContext As IServerContext = Nothing

        Dim agsServerConnection As ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection = Nothing

        Dim featuresCount As Integer

        Try

            Dim username As String = ConfigurationManager.AppSettings("username")
            Dim password As String = ConfigurationManager.AppSettings("password")
            Dim domain As String = ConfigurationManager.AppSettings("domain")
            Dim hostname As String = ConfigurationManager.AppSettings("hostname")
            Dim mapservice As String = ConfigurationManager.AppSettings("mapservice")

            ' Connect to ArcGIS Server
            Dim adfIdentity As New ESRI.ArcGIS.ADF.Identity(username, password, domain)
            agsServerConnection = New ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection(hostname, adfIdentity)
            agsServerConnection.Connect()

            If (Not agsServerConnection.IsConnected) Then

                agsServerConnection.Dispose()
                Return False

            End If

            ' Get a reference to the server object manager to use in creating server objects
            Dim serverObjectManager As ESRI.ArcGIS.Server.IServerObjectManager = agsServerConnection.ServerObjectManager

            ' Create a server context for and get a reference to the BloomfieldTownship map service.  We will
            ' use this to access map information and query features.
            mapServerContext = serverObjectManager.CreateServerContext(mapservice, "MapServer")

            Dim mapServer As ESRI.ArcGIS.Carto.IMapServer2 = TryCast(mapServerContext.ServerObject, ESRI.ArcGIS.Carto.IMapServer2)

            ' Get a reference to the map service's server objects

            Dim mapServerObjects As ESRI.ArcGIS.Carto.IMapServerObjects = CType(mapServer, ESRI.ArcGIS.Carto.IMapServerObjects)

            Dim map As ESRI.ArcGIS.Carto.IMap = mapServerObjects.Map(mapServer.DefaultMapName)

0 Kudos