您的位置:首页 > 其它

arcengine发布webservice编辑sde

2015-08-20 15:50 633 查看
        private IWorkspace GetWorkspace()

        {

            try

            {

                //注册许可

                ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Engine);

                ESRI.ArcGIS.esriSystem.IAoInitialize m_AoInit = new ESRI.ArcGIS.esriSystem.AoInitialize();

                if (!CheckOutLicenses(m_AoInit, esriLicenseProductCode.esriLicenseProductCodeArcServer))

                    return null;

                string server = ConfigurationManager.AppSettings["server"].ToString();

                //连接SDE

                IPropertySet propertySet = new PropertySet();

                propertySet.SetProperty("server", server);

                propertySet.SetProperty("instance", "sde:sqlserver:" + server);

                propertySet.SetProperty("database", ConfigurationManager.AppSettings["database"].ToString());

                propertySet.SetProperty("user", ConfigurationManager.AppSettings["user"].ToString());

                propertySet.SetProperty("password", ConfigurationManager.AppSettings["password"].ToString());

                propertySet.SetProperty("version", "SDE.DEFAULT");

                //创建工作工厂

                IWorkspaceFactory workspaceFactory = new SdeWorkspaceFactory();

                //打开工作空间

                IWorkspace workspace = workspaceFactory.Open(propertySet, 0);

                return workspace;

            }

            catch (Exception e)

            {

                WriteErrorLog(e);

                return null;

            }

        }

        /// 注册SDE服务

        /// <summary>

        /// 注册SDE服务

        /// </summary>

        /// <param name="m_AoInitialize">注册类</param>

        /// <param name="productCode">产品许可</param>

        /// <returns></returns>

        private bool CheckOutLicenses(ESRI.ArcGIS.esriSystem.IAoInitialize m_AoInitialize, esriLicenseProductCode productCode)

        {

            try

            {

                esriLicenseStatus licenseStatus;

                //是否产品是可能的

                licenseStatus = m_AoInitialize.IsProductCodeAvailable(productCode);

                if (licenseStatus == esriLicenseStatus.esriLicenseAvailable)

                {

                    //用相应的许可文件进行初始化

                    licenseStatus = m_AoInitialize.Initialize(productCode);

                    if (licenseStatus != esriLicenseStatus.esriLicenseCheckedOut)

                        return false;

                }

                else return false;

            }

            catch(Exception e)

            {

                WriteErrorLog(e);

                return false;

            }

            return true;

        }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  web service 链接sde