Solved! Go to Solution.
In the context of a layer object, layer visibility and the visible scale range for a layer are mutually exclusive. This is not intuitive. We've discussed this internally but have not come up with a cleaner implementation for the API. A layer's visible property can be true (and when it is, it should be included in the legend), but if you're outside the visible scale range for the layer, you do not see it on the map. This is what I was suggesting. If it's not what you're seeing, please contact support and log a bug.
Which version of server are you using (including service pack)? Generating legends via your own AGS instance requires 10.0 sp1 or later.
Do you see a request going to your legend endpoint when your app loads? I've attached a screen shot of what this looks like in chrome dev tools' network tab. Also, here's a working sample of using a dynamic layer and a legend: http://jsfiddle.net/kq6bx/
In BadLegend.png, is your map at a scale where your map service should be visible?
By default, the legend only displays info for visible layers. You can override this via a boolean constructor parameter called respectCurrentMapScale.