Connecting to AGS to get IMap

Want to know how connect to your AGS server and get a handle on IMap of your published AGS map service.  The following code should give you the basic bare bones code that you need in order to do that – note stuff in “” should be applicable to your environment.

BTW – I find that getting a handle on IMap is useful in a great many ArcObjects based programming – so just thought I should post.

private String _host = "myServerName";
private String _username = "joebloggs";
private String _password = "password";
private String _domain = "myDomainName";
public void connectToServer()throws IOException
    {
        try {
            IServerContext serverContext = null;
            IServerConnection serverConnection = new ServerConnection();
            ServerInitializer serverInitializer = null;
            IServerObjectManager som = null;

            serverInitializer = new ServerInitializer();
            serverInitializer.initializeServer(_domain, _username, _password);
            serverConnection.connect(_host);
            som = serverConnection.getServerObjectManager();
            serverContext = som.createServerContext("publishedMapServiceName", "MapServer");

            IMapServer mapServer = (IMapServer) serverContext.getServerObject();
            IMapServerObjects mapServObjs = (IMapServerObjects) mapServer;

            IMap map = mapServObjs.getMap(mapServer.getDefaultMapName());

            serverContext.releaseContext();

        } catch (UnknownHostException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (AutomationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
Advertisements
Connecting to AGS to get IMap

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s