6

I have just deployed an AGS-based application to our web server. This app worked great in development, but after deployment to the server I got the following error:

Unable to cast COM object of type 'System.__ComObject' to interface type 'ESRI.ArcGIS.Carto.IMapServerObjects'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{651521F3-AAFF-42B9-8C2D-1980625A13BF}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

The C# code generating this error is:

IServerContext context = som.CreateServerContext(ConfigurationManager.AppSettings["mapService"], "MapServer");
IMapServer mapServer = (IMapServer)context.ServerObject;
IMapServerObjects serverObjects = (IMapServerObjects)mapServer;

For some reason, the IMapServer instance cannot be casted to IMapServerObjects. What could be wrong?

2

2 Answers 2

5

The solution is to deploy the map service as an MXD. The MSD only supports a subset of ArcObjects.

2

In getting ready for ArcGIS Server 10.1 you may need to prepare yourself for MSD only MapServices. The recommend path forward is to use IMapServerDataAccess since you will no longer have IMapServerObjects. However, if you're like me, and really miss out on IMapServerObjects particular it's ability to provide you an IMap object, there's a workaround! This is based on the fact that ArcGIS Server deploys a similarly named MXD with the MSD. By finding out the name of the MXD you can use the IMapDocument object to open and from there, get your IMap object.

// C++ ArcObjects code sample

HRESULT GetIMap(IServerObjectHelper *pIServerObjectHelper, IMap **ppIMap)
{
    HRESULT hResult = S_OK;

    CComPtr<IServerObjectHelper2> ptrIServerObjectHelper2;
    pIServerObjectHelper->QueryInterface(IID_IServerObjectHelper2, (void**) &ptrIServerObjectHelper2);

    CComPtr<IPropertySet> ptrIPropertySet;
    hResult = ptrIServerObjectHelper2->get_ServerObjectProperty(&ptrIPropertySet);

    CComVariant varFilePath;
    hResult = ptrIPropertySet->GetProperty(CComBSTR("filePath"), &varFilePath);

    CComBSTR bstrMxdPath;
    LPTSTR pSlash = _tcsrchr(V_BSTR(&varFilePath), '\\');
    LPTSTR pExt = _tcsrchr((pSlash != NULL) ? pSlash : V_BSTR(&varFilePath), '.');
    bstrMxdPath.Append(V_BSTR(&varFilePath), (int) (pExt - V_BSTR(&varFilePath)));
    bstrMxdPath.Append(_T(".mxd"));

    CComPtr<IMapDocument> ptrIMapDocument;
    hResult = ptrIMapDocument.CoCreateInstance(CLSID_MapDocument);
    hResult = ptrIMapDocument->Open(bstrMxdPath, CComBSTR(""));

    CComPtr<IMap> ptrIMap;
    ptrIMap = NULL;
    hResult = ptrIMapDocument->get_Map(0, &ptrIMap);
    *ppIMap = ptrIMap.Detach();
    return S_OK;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.