locked
Plugin Deployment Queries? RRS feed

  • Question

  • Scenario:

    I've around 15 plugins for a CRM deployment and i register them in database using plugin registeration tool. while developing these tools, i added webservice reference which will eventually be written to app.Config file:

     <applicationSettings>
        <plugin2.Properties.Settings>
          <setting name="plugin2_CrmWsdl_CrmService" serializeAs="String">
            <value>http://srv:5555/MSCrmServices/2007/CrmService.asmx</value>
          </setting>
        </plugin2.Properties.Settings>
      </applicationSettings>
    


    Plus i define my crm webservice path in my code as well (for service object) :

          string orgName = "ABCEnterprises";
          string wUrl = "http://srv:5555/MSCrmServices/2007/CrmService.asmx";
          CrmService ser = new CrmService();
          ser.Url = wUrl;
          CrmAuthenticationToken myToken = new CrmAuthenticationToken();
          myToken.AuthenticationType = 0;
          myToken.OrganizationName = orgName.ToString();
          ser.CrmAuthenticationTokenValue = myToken;
          ser.Credentials = new NetworkCredential("administrator", "P123456", "domain");
    


    Question:

    If i want to deploy same plugins to some different server u in a similar manner (using plugin registeration tool and target to be DB), how can i change webservice url defined in app.Config? On compile, every plugin creates 1 DLL, 1 XML and 1 PDB file....Will i be supposed to change webservice path in XML files of everyyyy plugin?all 15 of them? is there a way to centralize this? whatever i've hard coded in C# code, i can read it from a custom XML file or from a registry, but how to change these webservice references written in Config-XML of a plugin with least efforts?


    Sohaib Ahmad [Business Management Solution Professional] http://www.solutiontalk.blogspot.com
    Wednesday, June 15, 2011 6:06 AM

Answers

  • Hi Andriy,

    I am not aware of this limitation, thanks for pointing it need to check this.

    Sohaib,

    1. using SDK API doesnt expose any custom entities. Thats why i am using webservice. Please correct me if i am wrong ----

    ---- Yes you are correct but you should use Dynamic entity for this, you can access your custom entity and custom attribute with dynamic entity.

    2. c# Hard coding is not the issue. I can read the same info from windows registry as well or i can write a custom.xml and keep it on c:\ and refer it in my code everywhere for allllllllllll of my plugin (please comment on 2nd approach - custom xml file). issue is related to webservice path written in appConfig file.

    ----- Instead of using custom xml file, it will be better to pass configuration data to plugin as suggested by Andriy.

    http://blogs.msdn.com/b/crm/archive/2008/10/24/storing-configuration-data-for-microsoft-dynamics-crm-plug-ins.aspx

    http://blog.customereffective.com/blog/2008/10/storing-configuration-data-for-plugins.html


    Mahain : My Dynamics CRM Blog

    Wednesday, June 15, 2011 6:49 AM
    Moderator
  • Hello,

    First thing - my name is Andriy.

    Second thing regarding the link - I will provide the code sample how you can pass parameters to plugins:

     

     

      public class RetrieveMultipleHandler : IPlugin
      {
        #region Privates
    
        private string webserviceur; = string.Empty;
    
        #endregion Privates
    
        #region CTOR
    
        public RetrieveMultipleHandler(string config, string secureconfig)
        {
    		webserviceurl = config;
        }
    
        #endregion CTOR
    
        #region IPlugin Members
    
        public void Execute(IPluginExecutionContext context)
        {
    		CrmService crmservice = new CrmService();
    		crmservice.Url = webserviceurl;
    	}
      }
    
    

     


    And the sample how to register such step - I used it in recently developed plugin:

     

     


    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Follow Andriy on Twitter
    Wednesday, June 15, 2011 6:44 AM
    Moderator

All replies

  • Hello Sohaib,

    Your app.Config fil will be ignored.

    You can use following approach - http://community.dynamics.com/product/crm/crmtechnical/b/crminogic/archive/2009/07/29/how-to-use-parameters-in-workflows-47-plugins.aspx

    Or you can get webservice url using following code -

    string webserviceurl = (string)(Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\MSCRM").GetValue("ServerUrl")) + "/2007/crmservice.asmx";


    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Follow Andriy on Twitter
    Wednesday, June 15, 2011 6:24 AM
    Moderator
  • First, instead of using webservice you should use SDK API for better performance

    but if you are using webservice, you should write configuration data in your webconfig instead of in code and then read if from webconfig file

    <appSettings>
        <add key ="OrganizationName" value =""/>
        <add key="UserID" value =""/>
        <add key ="Password" value =""/>
        <add key ="Domain" value =""/>
       <add key ="ServiceURL" value =""/>
      </appSettings >

    you can use below code tor read it.

                string UserID = ConfigurationSettings.AppSettings["UserID"];
                string Password = ConfigurationSettings.AppSettings["Password"];
                string Organame = ConfigurationSettings.AppSettings["OrganizationName"];
                string DomainName = ConfigurationSettings.AppSettings["Domain"];
               _Service.Url = ConfigurationSettings.AppSettings["ServiceURL"];

    if you are using the same plugin you just need to change webconfig files.

    Hope it will help.

     


    Mahain : My Dynamics CRM Blog

    Wednesday, June 15, 2011 6:25 AM
    Moderator
  • Hello Mahender,

    This would not work for Async Plugins as far as I know.


    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Follow Andriy on Twitter
    Wednesday, June 15, 2011 6:28 AM
    Moderator
  • Thanks Andriy and Mahendar.

    Andiry,

    The link you sent can help big time but registeration tool picture it shows is not readable. If you can understand it, can you please elaborate what has been written in unsecure configuration section? It seems like writer has copy-pasted the app.config file there. Is it so?

    Mahender,

    1. using SDK API doesnt expose any custom entities. Thats why i am using webservice. Please correct me if i am wrong.

    2. c# Hard coding is not the issue. I can read the same info from windows registry as well or i can write a custom.xml and keep it on c:\ and refer it in my code everywhere for allllllllllll of my plugin (please comment on 2nd approach - custom xml file). issue is related to webservice path written in appConfig file.


    Sohaib Ahmad [Business Management Solution Professional] http://www.solutiontalk.blogspot.com
    Wednesday, June 15, 2011 6:39 AM
  • Hello,

    First thing - my name is Andriy.

    Second thing regarding the link - I will provide the code sample how you can pass parameters to plugins:

     

     

      public class RetrieveMultipleHandler : IPlugin
      {
        #region Privates
    
        private string webserviceur; = string.Empty;
    
        #endregion Privates
    
        #region CTOR
    
        public RetrieveMultipleHandler(string config, string secureconfig)
        {
    		webserviceurl = config;
        }
    
        #endregion CTOR
    
        #region IPlugin Members
    
        public void Execute(IPluginExecutionContext context)
        {
    		CrmService crmservice = new CrmService();
    		crmservice.Url = webserviceurl;
    	}
      }
    
    

     


    And the sample how to register such step - I used it in recently developed plugin:

     

     


    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Follow Andriy on Twitter
    Wednesday, June 15, 2011 6:44 AM
    Moderator
  • Sorry for mis-spelling ur name Andriy.

    and thanks for the big help. in ur previous comment u mentioned mahendar's code wont work in ASynch plugins. Y not? can you please help me understanding issues with mahendar's approach and Aynch plugins?


    Sohaib Ahmad [Business Management Solution Professional] http://www.solutiontalk.blogspot.com
    Wednesday, June 15, 2011 6:49 AM
  • Hi Andriy,

    I am not aware of this limitation, thanks for pointing it need to check this.

    Sohaib,

    1. using SDK API doesnt expose any custom entities. Thats why i am using webservice. Please correct me if i am wrong ----

    ---- Yes you are correct but you should use Dynamic entity for this, you can access your custom entity and custom attribute with dynamic entity.

    2. c# Hard coding is not the issue. I can read the same info from windows registry as well or i can write a custom.xml and keep it on c:\ and refer it in my code everywhere for allllllllllll of my plugin (please comment on 2nd approach - custom xml file). issue is related to webservice path written in appConfig file.

    ----- Instead of using custom xml file, it will be better to pass configuration data to plugin as suggested by Andriy.

    http://blogs.msdn.com/b/crm/archive/2008/10/24/storing-configuration-data-for-microsoft-dynamics-crm-plug-ins.aspx

    http://blog.customereffective.com/blog/2008/10/storing-configuration-data-for-plugins.html


    Mahain : My Dynamics CRM Blog

    Wednesday, June 15, 2011 6:49 AM
    Moderator
  • Sorry for mis-spelling ur name Andriy.

    and thanks for the big help. in ur previous comment u mentioned mahendar's code wont work in ASynch plugins. Y not? can you please help me understanding issues with mahendar's approach and Aynch plugins?


    Sohaib Ahmad [Business Management Solution Professional] http://www.solutiontalk.blogspot.com
    This would not work because Async plugins are being executed with CrmAsyncService and this application doesn't know anything about web.config of Crm Website.

    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Follow Andriy on Twitter
    Wednesday, June 15, 2011 6:52 AM
    Moderator
  • Thanks alot both of you. Great posts clarifying sooo many misunderstanings.

    *CHEERS*


    Sohaib Ahmad [Business Management Solution Professional] http://www.solutiontalk.blogspot.com
    Wednesday, June 15, 2011 7:00 AM