web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to create CRM service in ASP.Net Web API

(0) ShareShare
ReportReport
Posted on by 233

Hi,

I am working on ASP.Net Web API and need to create CRM service to fetch data from CRM.

As I am using Web API class library how to configure CRM URL, Username and Pwd?

Please let me know what will be the approach to achieve this.

Thanks,

Yadav

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Shidin Haridas Profile Picture
    3,497 on at
    RE: How to create CRM service in ASP.Net Web API

    Hi Naveen,

    Install the following 2 packages:

    Install-Package Microsoft.CrmSdk.CoreAssemblies -Version 9.0.0.5

    Install-Package Microsoft.CrmSdk.XrmTooling.CoreAssembly -Version 9.0.0.5

    Once you have them installed, the following lines of code should be enough for you to connect to CRM. (Online or OnPrem)

    CrmServiceClient devCrmConn = new CrmServiceClient(ConfigurationManager.ConnectionStrings["DevCRM"].ConnectionString);

                   IOrganizationService _orgService = devCrmConn.OrganizationServiceProxy;

    I am reading from the app.config, where I have defined my Connection String as:

    <add name="DevCRM" connectionString="Url=YourCrmUrl;Username=YourUserName;Password=PassWord;AuthType=Office365" />

  • Suggested answer
    Justinjose Profile Picture
    2,707 on at
    RE: How to create CRM service in ASP.Net Web API

    Hi Naveen K,

    In addition to Shidin Haridas,  If you face TLS1.2 issue add following line before calling IOrganizationService.

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
    CrmServiceClient crmSvc = new CrmServiceClient(ConfigurationManager.ConnectionStrings["DevCRM"].ConnectionString);
    IOrganizationService _orgService = crmSvc.OrganizationWebProxyClient != null ? crmSvc.OrganizationWebProxyClient : (IOrganizationService)crmSvc.OrganizationServiceProxy;

    Thanks

    Justin Jose

  • Naveen K Profile Picture
    233 on at
    RE: How to create CRM service in ASP.Net Web API

    Hi,

    My question is, I am using class library and it wont' have app.config to store these details.

    I hope my question is clear now.

    Thanks,

    Naveen

  • Suggested answer
    Justinjose Profile Picture
    2,707 on at
    RE: How to create CRM service in ASP.Net Web API

    Hi Naveen, 

    Try following code

    public static class CRMConnection
        {
            public static CrmServiceClient GetCrmServiceClient()
            {
                var connectionString = @"AuthType=Office365;Username=; Password=;Url=";
                return new CrmServiceClient(connectionString);
    
            }
        }

    Or you can add in web config

    <connectionStrings>  
        <add name="Online" connectionString="; Username=; Password=; authtype=Office365" />
      </connectionStrings>
    
    public static class CRMConnection
           {
               public static CrmServiceClient GetCrmServiceClient()
               {
                   return new CrmServiceClient(ConfigurationManager.ConnectionStrings["Online"].ConnectionString);
               }
           }

    Thanks

    Justin Jose

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: How to create CRM service in ASP.Net Web API

    Hi Naveen ,

    I have given a sample of  console application in C# . You can have a look its similar -

    community.dynamics.com/.../273478

  • Nflannery Profile Picture
    360 on at
    RE: How to create CRM service in ASP.Net Web API

    The other posts were correct in terms of how to connect however I would recommend against storing usernames and passwords in app or web configs as they are not secure however in your scenario you seem like you would be unable to anyway.  If you are using Azure then use Azure Key Vault so store this information.

    community.dynamics.com/.../using-azure-key-vault-to-store-configuration-data

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

#3
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans