Hello,The problem is that the layer is not loaded before the TOC widget is loaded and therefore the TOC.js is hitting the ArcGIS legend service everytime because this.rootLayer.version is not yet populated. This widget will not work with internal only services not accessible to ArcGIS legend service. The proper solution is to check to see if the root layer is loaded before building the legend, if it is not loaded, then add and on("load") to the layer and call the _getLegendInfo. Here's the new code at around line 620 of TOC.js.
// extenstion point called by framework
postCreate: function () {
if ((this.rootLayer instanceof (ArcGISDynamicMapServiceLayer) ||
this.rootLayer instanceof (ArcGISTiledMapServiceLayer))) {
//check if the layer is loaded yet, if not, add a listener to wait
if (this.rootLayer.loaded) {
if (this._legendResponse) {
this._createRootLayerTOC();
} else {
this._getLegendInfo();
}
}
else {//layer not yet loaded, add listener
this.rootLayer.on("load", lang.hitch(this, this._getLegendInfo));
}
} else { //not servicelayer
this._createRootLayerTOC();
}
},