IWorkspace connection through WCF

804
2
03-16-2011 06:30 AM
LukeBadgerow
New Contributor
I have been working with a series of WPF controls within a custom add-in for ArcMap where the controls have a number of combo boxes that return the coded value domains for various features.  To return the coded values I am making a connection to SDE and pulling the values based on the String Name for the domain.  Visual Studio REALLY doesn't like to attempt to make that call out to SDE in the designer, which wrecks the entire solution, so I'm attempting to port that particular call to SDE over to a WCF service but I'm getting a COM exception (80040111) on the creation of my WorkspaceFactory (IWorkspaceFactory2).

        private IWorkspace OpenSDEWorkspace(String server, String instance, String database,
    String version, String user, String password)
        {
            try
            {
                String connectstring  = "SERVER=" + server
                    + ";DATABASE=" + database + ";INSTANCE=" + instance
                    + ";USER=" + user + ";PASSWORD=" + password + ";VERSION=" + version;

                IWorkspaceFactory2 sdeWorkspaceFactory;
                
                sdeWorkspaceFactory = (IWorkspaceFactory2)new SdeWorkspaceFactoryClass();
                IWorkspace workspace = (IWorkspace)sdeWorkspaceFactory.OpenFromString(connectstring,0);

                return workspace;
            }
            catch (Exception e)
            {
                throw new Exception(String.Format("arcSDEWorkspaceOpen: {0}", e.Message), e);
            }
        }


Any advice would be greatly appreciated.
0 Kudos
2 Replies
RoyDallal
New Contributor
Hi Luke,
First what license do you use? Because in order to use ArcObjects within a web service / WCF service you need ArcGis Server license (ArcEngine License doesn't work).
Secondly you need to initialize the license before using any ArcObject using (in ArcGis 10):
ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Server);
(see here for more information)

And before using IWorkspace I found you have to use the 9.3 license mechanizem:
IAoInitialize aoInit = new AoInitializeClass();
aoInit.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcServert);

(my unit test won't pass if I don't use both)

Hope it helps,
0 Kudos
LukeBadgerow
New Contributor
thanks!  That was what I was forgetting.  (I was having one of those days).
0 Kudos