Show Visible Unique Values in Legend for Dynamic Map Service Sublayer

Discussion created by krobine on Jan 18, 2013
I was wondering how to do the following:

I have a DynamicMapService with a sublayer that is classified on unique values. There are probably 20 or more values. What I want to do is have the legend update showing only the values that are currently visible, at the current extent.

Possible with the JavaScript API? It's not clear to me how to do this. 
I would be interested in hearing any server-side solutions to this.  Maybe a geoprocessing service or a Server Object Extension can do this?