ArcGIS API for JavaScript: LayersAsKML/KMLTest (MapServer)
Built using the
ArcGIS API for JavaScript