tips & tricks


Calendario
aprile 2024
lmmgvsd
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345

ServiceActivator - una comoda classe per attivare i servizi del crm.

Buongiorno a tutti,
Utilizzo spesso nei progetti di crm una classe che istanzia i servizi del crm costruendo l'url a partire dal registry, in modo che non bisogna mettere le mani al codice nel caso che dovesse cambiare l'indirizzo del crm.....per esempio quando vai a fare un deploy dal cliente.


        public static CrmService GetCrmService()
        {
            CrmService service = new CrmService();
            service.Credentials = System.Net.CredentialCache.DefaultCredentials;

            SetupWebServiceUrl(service);

            return service;
        }

//recupera URL del CRM
     
        public static string GetServerUrl()
        {
            RegistryKey key;
            string result;

            key = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\MSCRM", false);
            result = (string)key.GetValue("ServerUrl");
            result = result.Replace("/MSCRMServices", "");
            return result;
        }

//Costruisco l'url

        private static void SetupWebServiceUrl(CrmService service)
        {
            string urlSetting = System.Configuration.ConfigurationSettings.AppSettings["ConpanyName.Crm.Components.Core.WSCrmService.CrmService"];
           
            RegistryKey key = null;
           
            if (urlSetting != null)
                return;

            try
            {
                key = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\MSCRM", false);

                urlSetting = (string)key.GetValue("ServerUrl");
                urlSetting = Path.Combine(urlSetting, @"2006\CrmService.asmx");   
               
            }
            catch (Exception ex)
            {
                string msg = "Exception occurred while reading Crm service url.";
                msg += "{0}Type: {1}";
                msg += "{0}Message: {2}";
                msg += "{0}StackTrace: {3}";
                msg = string.Format(msg, Environment.NewLine, ex.GetType(), ex.Message, ex.StackTrace);

                Trace.WriteLine(msg);
            }
            finally
            {
                if (key != null)
                    key.Close();
            }       
   
            if (urlSetting != null)
                service.Url = urlSetting;
        }


Altri metodi comodi possono essere:

        public static string GetSQLConnectionString()
        {
            RegistryKey key;
            string result;

            key = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\MSCRM", false);

            //Provider=SQLOLEDB;Data Source=BSSSQL01;Initial Catalog=CompanyName_MSCRM;Integrated Security=SSPI

            result = (string)key.GetValue("database");
            result = result.Replace("Provider=SQLOLEDB;", "");
            return result;
        }

       public static string GetReportUrl()
       {
          RegistryKey key;
          string result;

          key = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\MSCRM", false);
          result = (string)key.GetValue("SQLRSServerURL");
          return result;
       }


Categoria: CRM 3.0
venerdì, 05 set 2008 Ore. 10.24
Archivio Posts
Anno 2020

Anno 2018

Anno 2015

Anno 2013

Anno 2011

Anno 2010

Anno 2009

Anno 2008
Statistiche
  • Views Home Page: 13.299
  • Views Posts: 56.000
  • Views Gallerie: 2.837
  • n° Posts: 117
  • n° Commenti: 1
Copyright © 2002-2007 - Blogs 2.0
dotNetHell.it | Home Page Blogs
ASP.NET 2.0 Windows 2003