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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Connecting Azure to Dcrm but getting erro

(0) ShareShare
ReportReport
Posted on by

Hi All,

I am preferring below code.

using System;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.ServiceModel.Description;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;

namespace CRM.AzureFunction.Integration
{
public static class Function1
{
[FunctionName("Function1")]
public static Task RunAsync([HttpTrigger(AuthorizationLevel.Anonymous, "POST", Route = null)] HttpRequestMessage req, TraceWriter log)
{


log.Info("C# HTTP trigger function processed a request.");

IOrganizationService service = Connection(log);
if (service != null)
{
//If Connection is established
Entity account = new Entity("account");
account["name"] = "Created from the azure function";
service.Create(account);

}

return Task.CompletedTask;
}

private static IOrganizationService Connection(TraceWriter log)
{
IOrganizationService service = null;

#region Credentials Code
//Credentials
string URL = """;
string userName = "";
string password = "";
#endregion

try
{
ClientCredentials clientCredentials = new ClientCredentials();
clientCredentials.UserName.UserName = userName;
clientCredentials.UserName.Password = password;


// ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

OrganizationServiceProxy ornaziationServiceProxy = new OrganizationServiceProxy(new Uri("" + URL + "/XRMServices/2011/Organization.svc"), null, clientCredentials, null);

// ornaziationServiceProxy.Timeout = new TimeSpan(0, 10, 0);

service = ornaziationServiceProxy;

if (service != null)
{
Guid userid = ((WhoAmIResponse)service.Execute(new WhoAmIRequest())).UserId;

if (userid != Guid.Empty)
{
log.Info("Connection Established Successfully...");
}
}
else
{
log.Error("Failed to Established Connection!!!");
}
}
catch (Exception ex)
{
log.Error("Exception caught - " + ex.Message);
}

return service;
}
}
}

Getting error please see the below screenshot 

Please help me on this.

Thanks,

Arshad

I have the same question (0)
  • Sourav0147 Profile Picture
    115 on at

    Can you please uncomment the below code and try

    // ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12.

    Do you have MFA enabled for the user which you are trying to login?

  • Community Member Profile Picture
    on at

    Hi,

    I have created the video on azure function. In video i have created the record in dcrm using azure function.

    https://youtu.be/X7H25FZHoF0     

    https://juniorazurecrm.blogspot.com/   App Registration 

    https://juniorcrmblog.blogspot.com/

    Thanks,

    Arshad

  • Suggested answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    Hi,

    You should use CrmServiceClient class to connect to Dnamics CRM. Please see below article for the same

    carldesouza.com/.../

    Also, make sure you are providing correct password and username.

    Please mark my answer verified if this is helpful!

    Regards,

    Bipin Kumar

    Follow my Blog: xrmdynamicscrm.wordpress.com/

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 70 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 33 Most Valuable Professional

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans