WMS and ArcGIS MapService layer not exported by ActiveView

Discussion created by bsundsbo on Nov 1, 2010
Sorry for the duplicate of previous thread. I can't edit the original post to contain more up to date details (the information seems to drown in the original post for new readers).

I use IMapDocument and its ActiveView.Output to export a bitmap from an MXD documen to a bitmap. This works just fine with an MXD with local data. However, when exporting from an MXD with a WMS or ArcGIS Server Map Service layer, the layer is not exported to the hdc.

When exporting the WMS or AGS MS layer, a PNG for the requested area is created in the temp folder for my user (with the correct content). The output method fails in other words to draw that layer onto the hdc passed into the Output method.

I am able to work around the issue with Mas Server layer by setting the output type to MIME instead of MIME + URL, however, the same thing can't be done with the WMS service as it is not ours.

Why is the Output method not rendering the WMS and ArcGIS Map layers to the hdc when it is obviously retrieving the image and should be able to do so? And how can I fix this?

Here is the code used for exporting the map (ArcGIS Engine 9.3.1):
private void Export(IEnvelope extent)
      _mapDocument= new MapDocument();
      _mapDocument.Open("path", null);
      // ..
      _mapDocument.ActiveView.Extent = extent;
      var image = GetImageFromJpegExporter(rect, null);
      // ...

private Bitmap GetImageFromJpegExporter(tagRECT rect, CancelTracker trackCancel) {
      string filename = Guid.NewGuid().ToString();
            tagRECT exportRECT = _mapDocument.ActiveView.ExportFrame;

            //Create a new envelope object and populate it with the values from exportRECT.
            // We need to do this because the exporter object requires an envelope object
            // instead of a tagRECT structure.
            IEnvelope pPixelBoundsEnv = new EnvelopeClass();
            pPixelBoundsEnv.PutCoords(exportRECT.left,, exportRECT.right, exportRECT.bottom);

            IExport export = new ExportPNGClass
                  Resolution = 96,
                  ExportFileName = filename,
                  PixelBounds = pPixelBoundsEnv

            int hwnd = export.StartExporting();
            _mapDocument.ActiveView.Output(hwnd, 96, ref rect, _mapDocument.ActiveView.Extent, trackCancel);

            Bitmap fromFileBitmap = new Bitmap(filename);
            // Copy fromFileBitmap because it keeps a lock on the file
            Bitmap returnBitmap = new Bitmap(fromFileBitmap);
            return returnBitmap;
                  catch (Exception)



Bjørnar Sundsbø