Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

Not able to connect to CRM from Azure Function

Posted on by 30

Hi,

I have an azure function whose first step is to connect to CRM

following is my code:

public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "POST", Route = null)] HttpRequestMessage req, TraceWriter log)
{

IOrganizationService service = null;
string URL = "">https://xyz.crm.dynamics.com";
string userName = "cf_admin@xyz.com";
string password = "xyz";
// var res = Environment.GetEnvironmentVariable($"URL");

ClientCredentials clientCredentials = new ClientCredentials();
clientCredentials.UserName.UserName = userName;
clientCredentials.UserName.Password = password;
OrganizationServiceProxy organizationServiceProxy = new OrganizationServiceProxy(new Uri("" + URL + "/XRMServices/2011/Organization.svc"), null, clientCredentials, null);
//For Dynamics 365 Customer Engagement V9.X, set Security Protocol as TLS12
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
organizationServiceProxy.Timeout = new TimeSpan(0, 10, 0);
service = (IOrganizationService)organizationServiceProxy;

I published the function into azure portal, when I hit the azure function, but it is not connecting to CRM.

Locally this is working perfectly fine but when debugging the code from azure cloud service it does not connects to CRM.

It is giving the following error:

pastedimage1606819567626v1.jpeg

Any help is appreciated.

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Not able to connect to CRM from Azure Function

    Hello,

    Check my post on usage of CrmServiceClient - butenko.pro/.../

    You have to prepare the connection string and use CrmServiceClient from the latest SDK package.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans