0

I have this end point to my ArcGIS Server: http://myarcgisserver/arcgis/rest/services/prueba/GMRE/MapServer

I'm trying it with GisClient:

public void requestServer(string username, string password)
    {

        string url = "http://myarcgisserver/arcgis/rest/services/prueba/GMRE/MapServer";
        var gisServer = OpenConnection(url);
        MessageBox.Show(gisServer.ToString());

    }


private static IAGSServerConnection OpenConnection(string svcUrl)
    {
        //create a property set to hold connection properties
        var connectionProps = new PropertySet() as IPropertySet;
        //specify the URL for the server
        connectionProps.SetProperty("URL", svcUrl);

        //create a new ArcGIS Server connection factory
        var connectionFactory = (IAGSServerConnectionFactory2)new AGSServerConnectionFactory();
        var gisServer = connectionFactory.Open(connectionProps, 0);
        System.Runtime.InteropServices.Marshal.FinalReleaseComObject(connectionFactory);
        return gisServer;
    }

But I get a exception saying 'Invalid url'

My service in the browser:

enter image description here

How can I consume it from arcobjects?

1

Often, when constructing ArcGIS Server service URLs you need to include the type of service you're connecting to in the URL, such as MapServer for a standard map service.

Try changing your URL to something like "http://myarcgisserver/arcgis/rest/services/prueba/MapServer"

See Components of ArcGIS URLs - ArcGIS Server end user URLs, specifically the section labelled "ArcGIS services", and see the table "REST service values" if MapServer is not correct for your URL.

  • I added the type service 'MapServer', but I still getting the exception with invalid url message – Pilgrim May 22 '17 at 16:28
  • @Manso If you go to that URL in your browser, does it open it? – Midavalo May 22 '17 at 16:45
  • Yes, I added a picture – Pilgrim May 22 '17 at 16:49
  • @Manso Note that the URL in your browser is different than the one in your question. You are missing GMRE in your question. – Midavalo May 22 '17 at 16:54
  • I gonna correct it for the url that now I'm trying – Pilgrim May 22 '17 at 16:59
0

Not sure if this helps, but here's how I have queried an ArcGIS Server Feature Service in the past:

//query objectid = 1
string url = @"https://my.arcgis.server/arcgis/rest/services/MyProject/MapServer/0/query?where=OBJECTID=1&text=&objectIds=&time=&geometry=&geometryType=esriGeometryPoint&inSR=&spatialRel=esriSpatialRelIntersects&relationParam=&outFields=*&returnGeometry=false&returnTrueCurves=false&maxAllowableOffset=&geometryPrecision=&outSR=&returnIdsOnly=false&returnCountOnly=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=&returnZ=false&returnM=false&gdbVersion=&returnDistinctValues=false&resultOffset=&resultRecordCount=&f=pjson";
string json;

using (WebClient w = new WebClient())
{
    StreamReader sr = new StreamReader(w.OpenRead(queryUrl));
    json = sr.ReadToEnd();
    sr.Close();
}

where json is a JSON string you can deserialize to an object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.