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

  • Suggested answer
    Bipin D365 Profile Picture
    28,981 Moderator on at
    RE: Connecting Azure to Dcrm but getting erro

    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/

  • Community Member Profile Picture
    on at
    RE: Connecting Azure to Dcrm but getting erro

    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

  • Sourav0147 Profile Picture
    115 on at
    RE: Connecting Azure to Dcrm but getting erro

    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?

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 225 Super User 2025 Season 1

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 97

#3
Vahid Ghafarpour Profile Picture

Vahid Ghafarpour 82 Super User 2025 Season 1

Overall leaderboard

Product updates

Dynamics 365 release plans