MapServerQuerySublayer (Version 10) does not seem to support setting a definition query, although according to documentation it should using ImapServerSublayer2.LayerDescription as IMapserverSublayer. Nor does it support selections, i.e. rendering objects matching a query or selection differently.

What are our options when making an Engine application which contains a MapControl consuming only arcgisserver layers? In the application we would like to change an individual layer's definition query to only show object that matches the user's interest. We would also like to render some objects as "selected" to reflect user selections.

It would also be nice to be able to get the selected objects to the client as features, which also does not seem to be supported out of the box in ArcGisServer.

Any ideas on how to accomplish this?

Edit:

I don't think that we can wait for ESRI to fix this bug, so I'm looking for an alternate solution, which may include fetching the selection as features and use a local layer. Engine seems to lack support for fetching features from a map service without having to connect to the context itself (not using the Layer's connection) or fetching them one by one using identify. Using the Feature service seems like a good idea, but Engine has no built in functionality to from a Layer fetch IFeatures from the FeatureService. I think that there would be a more graceful way than having to involve extra connections to the server, which implies more configuration in the application.

Have you considered using the Silverlight/WPF sdk instead of arcengine? I think the FeatureLayer.where works. Besides, it's free and certainly much easier to deploy than arcengine.
–
Kirk KuykendallFeb 10 '11 at 14:45

petr: I missed that Mattias had posted a similar question, we're actually working on the same project.
–
StefanFeb 11 '11 at 9:41

@Kirk We dismissed Silverlight a long time ago. The application is actually doing a lot more that is hard to accomplish in silverlight. For this question its only the AGSserver layers that are interesting.
–
StefanFeb 11 '11 at 10:06

When implementing the custom layer, it's also possible to stay in the ArcObjects world by using IMapServer. IMapServer.ExportMapImage takes an IMapDescription, where definition expressions for individual layers can be specified. This approach would actually mean reimplementing the existing layer objects, but working around the bugs it has.
–
Petr KrebsFeb 11 '11 at 17:16

This isn't a bug, the functionality is just not implemented for the layer. Specifically IMapServerSublayer2.get_LayerDescription hands out a copy of the description, not an updatable reference. In almost all cases the ArcObjects help will list an object as get/put_ref if the accessor hands out a reference. The are occasionally usages of get/put for objects, but these are rare. This particular member has no put equivalent.

If you are just using service layers for an engine application, I'd recommend using the Silverlight/WPF API instead. It has everything you are looking for and excellent query support.

Then this behaviour should be clearly documented. I can think of many, many examples when the "rule" you describe does not apply. Anyway, from my point of view, my definition of a bug, by which I myself develop software, is that when the user or consumer of my API perceives something as a bug, then it IS a bug.
–
Petr KrebsFeb 13 '11 at 10:33

@craig-williams well that it works in other ESRI APIs and doesn't work in ArcObjects is the reason I consider this to be a bug.
–
MathiasWestinFeb 14 '11 at 8:37

ok, good resource to clarify the behavior. Still, I have always found it largery inconsistent. Anyway, the point is, for this particular property, there should be a means to change it, otherwise it is a quite an important feature missing in AO.
–
Petr KrebsFeb 14 '11 at 9:17

Understood. The AO MapServerLayer does not expose the full functionality of the MapService and that is the primary complaint.
–
Craig WilliamsFeb 14 '11 at 19:54

The NIM063392 has been logged for the issue that IMapServerSubLayer doesn't honor ILayerDescription property DefinitionExpression. I have looked into the status of this NIM and it had been exported to the development team for a possible fix, but hasn't been fixed yet.

I found the issue root is actually caused by [NIM036788 Make IMapServeSubLayer::LayerDescription Read/Write. It is currently Read only.] Our developer replied in NIM036788 that

"IMapServeSubLayer::LayerDescription is read only. You will not be
able to apply a new definition expression through a MapServerSubLayer.
You would have to access the MapServer through the context requiring a
DCOM connection. There is no workaround for an internet connection."

The only option is to use aDCOM connection to access the IMapServer object. For example: