locked
To store password in Crediental.XML file RRS feed

  • Question

  • XElement configurationsFromFile = XElement.Load(CrmServiceHelperConstants.ServerCredentialsFile); foreach (XElement config in configurationsFromFile.Nodes()) { Configuration newConfig = new Configuration(); var serverAddress = config.Element("ServerAddress"); if (serverAddress != null) if (!String.IsNullOrEmpty(serverAddress.Value)) newConfig.ServerAddress = serverAddress.Value; var organizationName = config.Element("OrganizationName"); if (organizationName != null) if (!String.IsNullOrEmpty(organizationName.Value)) newConfig.OrganizationName = organizationName.Value; var discoveryUri = config.Element("DiscoveryUri"); if (discoveryUri != null) if (!String.IsNullOrEmpty(discoveryUri.Value)) newConfig.DiscoveryUri = new Uri(discoveryUri.Value); var organizationUri = config.Element("OrganizationUri"); if (organizationUri != null) if (!String.IsNullOrEmpty(organizationUri.Value)) newConfig.OrganizationUri = new Uri(organizationUri.Value); var homeRealmUri = config.Element("HomeRealmUri"); if (homeRealmUri != null) if (!String.IsNullOrEmpty(homeRealmUri.Value)) newConfig.HomeRealmUri = new Uri(homeRealmUri.Value); var vendpointType = config.Element("EndpointType"); if (vendpointType != null) newConfig.EndpointType = RetrieveAuthenticationType(vendpointType.Value); if (config.Element("Credentials").HasElements) { newConfig.Credentials = ParseInCredentials(config.Element("Credentials"), newConfig.EndpointType, newConfig.ServerAddress + ":" + newConfig.OrganizationName + ":" + config.Element("Credentials").Element("UserName").Value); }

    Hi,

    I have used Early binding to connect with CRM 2011. In that I have used the helper class which is present in the Sample folder in SDK in that all the values are fetched from the Crediental.XML file In that password is not stored it is taken from the user now I do not want to key in Please help .. my XML file is, where to store it and how to retrieve the same in Helper class

    <?xml version="1.0" encoding="utf-8"?>
    <Configurations>
      <Configuration>
        <ServerAddress>xtttt</ServerAddress>
        <OrganizationName>crmttt</OrganizationName>
        <DiscoveryUri>http://xtttt/XRMServices/2011/Discovery.svc</DiscoveryUri>
        <OrganizationUri>http://xtttt/crmttt/XRMServices/2011/Organization.svc</OrganizationUri>
        <HomeRealmUri>
        </HomeRealmUri>
        <Credentials>
          <UserName>b.ttt</UserName>
          <Domain>Domainttt</Domain>
        </Credentials>
        <EndpointType>ActiveDirectory</EndpointType>
        <UserPrincipalName>
        </UserPrincipalName>
      </Configuration>
    </Configurations>


     
    Monday, August 26, 2013 11:01 AM

All replies

  • Hi,

        It would be possible for you to encrypt the password and store in the config file. Hold the details to decrypt in memory of your code and decrypt it when creating the credentials record. Only issue is you need to create a separate console app to encrypt.


    Hope this helps.
     
    -----------------------------------------------------------------------
     Minal Dahiya
     
    If this post answers your question, please click "Mark As Answer" on the post and "Vote as Helpful"

    Monday, August 26, 2013 11:12 AM
  • Hi ,

    Thanks for your reply..

    I want do not want to encrypt the password then, My problem is how to store in XML as I have tried to create a password tag in Credentials Node and also changed the

      if (config.Element("Credentials").HasElements)
                       
    {
                            newConfig
    .Credentials =
                               
    ParseInCredentials(config.Element("Credentials"),
                                newConfig
    .EndpointType,
                                newConfig
    .ServerAddress + ":" + newConfig.OrganizationName + ":" + config.Element("Credentials").Element("UserName").Value);
                       
    }

    section to get the password but further in the code it stuck.

    Thanks

    Monday, August 26, 2013 11:45 AM
  • Assuming you are using a Console Application, you can store the CRM credentials inside the app.config file. For example:

      <appSettings>
        <add key="sdkurl" value="http://server/XrmServices/2011/Discovery.svc"/>
        <add key="domain" value="domain"/>
        <add key="username" value="user/>
        <add key="password" value="Passw0rd"/>
        <add key="org" value="myorg"/>
      </appSettings>

    Then, inside your C# code, you can simple grab the details using the ConfigurationManager.

                        string serverAddress = ConfigurationManager.AppSettings["sdkurl"];
                        string domain = ConfigurationManager.AppSettings["domain"];
                        string username = ConfigurationManager.AppSettings["username"];
                        string password = ConfigurationManager.AppSettings["password"];
                        string org = ConfigurationManager.AppSettings["org"];

    No need for any complicated XML parsing. I hope this helps.
    • Proposed as answer by Roshan Mehta Wednesday, August 28, 2013 9:42 AM
    Wednesday, August 28, 2013 9:42 AM