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(); } }

No comments yet
Comments feed for this article