E_FAIL when calling IImageServer.Initialize()

663
4
12-16-2011 04:21 PM
IrohBrown
New Contributor
I am using ArcGIS Engine and Developer Kit 10 on Windows 7. Specifically, I'm writing an ArcObjects console program using Visual C# Express 2008.

I am attempting connect to an image server via a URL (e.g. http://server/.../ImageServer), but I get an HRESULT E_FAIL exception when I call IImageServerLayer.Initialize(). The full message is "Error HRESULT E_FAIL has been returned from a call to a COM component." There isn't much information on this error. Any advice on what could be wrong? Here's my code:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using ESRI.ArcGIS.esriSystem;
    using ESRI.ArcGIS.Geodatabase;
    using ESRI.ArcGIS.Carto;
    using ESRI.ArcGIS.Geometry;
    using ESRI.ArcGIS.DataSourcesRaster;
    using ESRI.ArcGIS.GISClient;
    
    namespace EngineConsoleApplication1
    {
        class Program
        {
            private static LicenseInitializer m_AOLicenseInitializer = new EngineConsoleApplication1.LicenseInitializer();
        
            [STAThread()]
            static void Main(string[] args)
            {
                //ESRI License Initializer generated code.
                m_AOLicenseInitializer.InitializeApplication(new esriLicenseProductCode[] { esriLicenseProductCode.esriLicenseProductCodeEngine },
                new esriLicenseExtensionCode[] { esriLicenseExtensionCode.esriLicenseExtensionCode3DAnalyst, esriLicenseExtensionCode.esriLicenseExtensionCodeNetwork, esriLicenseExtensionCode.esriLicenseExtensionCodeSpatialAnalyst, esriLicenseExtensionCode.esriLicenseExtensionCodeSchematics, esriLicenseExtensionCode.esriLicenseExtensionCodeMLE, esriLicenseExtensionCode.esriLicenseExtensionCodeDataInteroperability, esriLicenseExtensionCode.esriLicenseExtensionCodeTracking });
                //ESRI License Initializer generated code.
                //Do not make any call to ArcObjects after ShutDownApplication()
    
                //Create an image server layer by passing a URL.
                IImageServerLayer imageserverlayer = new ImageServerLayerClass();
                string URL = "http://vega/ArcGIS/rest/services/grandcanyon/ImageServer";
                imageserverlayer.Initialize(URL); // "Error HRESULT E_FAIL has been returned from a call to a COM component."
    
                //Get the raster from the image server layer.
                IRaster raster = imageserverlayer.Raster;
    
                //The raster from an image server is normally large; 
                //define the size of the raster.
                IRasterProps rasterProps = (IRasterProps)raster;
                IEnvelope clipEnvelope = new EnvelopeClass();
                clipEnvelope.PutCoords(779000, 9628000, 786000, 9634000);
                rasterProps.Extent = clipEnvelope;
                rasterProps.Width = 256;
                rasterProps.Height = 256;
    
                //Save the clipped raster to the file geodatabase.
                ISaveAs saveas = (ISaveAs)raster;
                Type factoryType = Type.GetTypeFromProgID(
                    "esriDataSourcesGDB.FileGDBWorkspaceFactory");
                IWorkspaceFactory workspaceFact = (IWorkspaceFactory)Activator.CreateInstance
                    (factoryType);
                IWorkspace workspace = workspaceFact.OpenFromFile(@"c:\temp\fgdb.gdb", 0);
                saveas.SaveAs("clipfromimageserverlayer", workspace, "gdb");
                
                m_AOLicenseInitializer.ShutdownApplication();
            }
        }
    }


This code is based on http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//00010000047t000000.

Here's the exception detail provided by Visual C#'s error dialog:

    System.Runtime.InteropServices.COMException was unhandled
      Message="Error HRESULT E_FAIL has been returned from a call to a COM component."
      Source="ESRI.ArcGIS.Carto"
      ErrorCode=-2147467259
      StackTrace:
           at ESRI.ArcGIS.Carto.ImageServerLayerClass.Initialize(String ServiceURL)
           at EngineConsoleApplication1.Program.Main(String[] args) in C:\Users\brown\AppData\Local\Temporary Projects\EngineConsoleApplication1\Program.cs:line 35
           at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
           at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()
      InnerException:
0 Kudos
4 Replies
RichardWatson
Frequent Contributor
I don't know anything about image services but am wondering if the issue might lie in URL.

Have you tried to monitor, say via Fiddler, the HTTP traffic to this URL?
0 Kudos
IrohBrown
New Contributor
Thanks for your reply. I tried loading the URL in a browser and I can access the web interface for the image server. Could there be a different problem with the URL?
0 Kudos
RichardWatson
Frequent Contributor
The ESRI code will issue various HTTP requests to the URL and Fiddler will let you see the results.  Knowing whether or not an error is returned would be helpful in debugging your problems.
0 Kudos
IrohBrown
New Contributor
Turns out you need to provide the URL to the SOAP version of the ImageServer. You can obtain this by opening the ImageServer's REST address in a browser (e.g. http://vega/ArcGIS/rest/services/GalleCrater/ImageServer) and clicking on the SOAP link at the bottom. The resulting URL looks something like http://vega/ArcGIS/services/GalleCrater/ImageServer?wsdl. Also, the C# program still works if I exclude the "?wsdl" suffix.
0 Kudos