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.
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...
I believe you have to do it through map services. After searching for a long time I found this
ArcGIS Runtime for .NET against Enterprise geodatabase -> Supported only if using services
I hope someone proves me wrong.
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"));
//add the layer to the map and zoom to its extent
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.ReturnGeometry = true;
QueryResult myResult = await myQueryTask.ExecuteAsync(myQuery);
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 )
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
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)
If (Not agsServerConnection.IsConnected) Then
' 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)