I've published an ArcServer service that is going to be consumed by out of the box, standard ArcGIS on the desktop.
Is it possible to write custom tools in VB to query layers from that service in the ArcMap interface?
I'm using ArcGIS 9.3.
Yes, you can. Basically, you have two options to query ArcGIS Server layers in ArcMap via ArcObjects.
The first way is to get a reference to an individual AGS sublayer (IMapServerSubLayer). Those layers (i.e. sublayers in this context) which have the Query capability enabled can be cast to IFind interface. You can use this interface to perform simple (and quite limited) querying.
The second way means getting access to the actual AGS server object and making use of its search capabilities. First you get a reference to the top-level AGS layer (IMapServerLayer) and use its GetConnectionInfo method to obtain information about the connection. Then you would get access to the server object (map server) and call one of the IMapServer methods, such as QueryFeatureData. This approach is much more involved (see my example code), but the search is not as limited as in the first case.
Dim pAgsLayer As IMapServerLayer
' ... get reference to the top-level AGS layer somewhere, e.g. from the TOC ...
Dim pSoName As IAGSServerObjectName
Dim pName As IName
Dim pMapServer As IMapServer
Dim sDocLocation As String, sMapName As String
Dim pRecordSet As IRecordSet
Dim pQueryFilter As IQueryFilter
' get access to the layer's AGS map server object
pAgsLayer.GetConnectionInfo pSoName, sDocLocation, sMapName
Set pName = pSoName
Set pMapServer = pName.Open
' specify some query conditions
Set pQueryFilter = New QueryFilter
pQueryFilter.SubFields = "*"
pQueryFilter.WhereClause = "OBJECTID = 1"
' query the layer with Id 0 (the first layer in the map service)
Set pRecordSet = pMapServer.QueryFeatureData(sMapName, 0, pQueryFilter)
Dim pCursor As ICursor
Dim pRow As IRow
Set pCursor = pRecordSet.Cursor(True)
Set pRow = pCursor.NextRow
' loop through the results and do something with them
Do While Not pRow Is Nothing
Debug.Print pRow.OID
Set pRow = pCursor.NextRow
Loop