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

Unable to connect to D365 from Azure functions

(1) ShareShare
ReportReport
Posted on by 15

Hello,

I am trying to connect to my D365(CE) instance from an Azure Function. I have tried the multiple options found on the internet but the XRM Tooling connection is failing.

Following are the details 

D365 instance  version: Server version: 9.1.0000.17446(2020 release wave 1 enabled)

D365 SDK :microsoft.crmsdk.xrmtooling.coreassembly.9.1.0.42

Azure Function Run time version: 1

Azure Function Trigger: HTTP C#

Code:

#r "Newtonsoft.Json"
#r "System.Configuration"
#r "Microsoft.IdentityModel.Clients.ActiveDirectory.dll"
#r "Microsoft.Xrm.Sdk.dll"
#r "Microsoft.Xrm.Tooling.Connector.dll"
using System.Net; 
using System.Configuration;
using System.Security.Claims; 
using System.Net.Http.Headers;
using Newtonsoft.Json;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using System.Net; 
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Client;
using System.ServiceModel.Description;
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Tooling.Connector;
using Microsoft.IdentityModel.Clients.ActiveDirectory;

public static async Task Run(HttpRequestMessage req, TraceWriter log)
{
    log.Info("C# HTTP trigger function processed a request.");

    // parse query parameter
    string name = req.GetQueryNameValuePairs()
        .FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0)
        .Value;

    if (name == null)
    {
        // Get request body
        dynamic data = await req.Content.ReadAsAsync();
        name = data?.name;
    }

     ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

    CrmServiceClient client = new CrmServiceClient("AuthType=Office365;Username=**@***.onmicrosoft.com;Password=****;Url=https://****.crm4.dynamics.com");
    if (client.LastCrmError != "" && client.LastCrmError != null)
                        {
                            throw new Exception(client.LastCrmError);
                        }

    return name == null
        ? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name on the query string or in the request body")
        : req.CreateResponse(HttpStatusCode.OK, "Hello "  name);
}

 Error : Unable to connect to CRM: Method not found: 'Void Microsoft.Crm.Sdk.Messages.RetrieveCurrentOrganizationRequest.set_AccessType(Microsoft.Xrm.Sdk.Organization.EndpointAccessType)'. Method not found: 'Void Microsoft.Crm.Sdk.Messages.RetrieveCurrentOrganizationRequest.set_AccessType(Microsoft.Xrm.Sdk.Organization.EndpointAccessType)'.Unable to Login to Dynamics CRM Unable to Login to Dynamics CRM.

0045.Capture.JPG

Has anyone tried this?  Most of the articles I found on internet is connecting using old SDK which won't work for connecting to the latest instances.

PS:  There are many unwanted libraries referred in the code, I believe that won't cause any issues at this stage.

Many thanks in advance.

 

I have the same question (0)
  • Suggested answer
    Anupam.khasia Profile Picture
    170 on at

    Hi Kiran S, 

    Can you check your Azure function runtime version ? XRMTooling supports only .Net framework 4.6.2 . Check which Runtime version you have selected during creating project. 

    https://www.nuget.org/packages/Microsoft.CrmSdk.XrmTooling.CoreAssembly/

    https://docs.microsoft.com/en-us/azure/azure-functions/functions-develop-vs

    If this helps, please mark it verified.

  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at

    Hi,

    Did you check my post: himbap.com/.../

    I am connecting to Dynamics 365 using Application user

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 83 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

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

#3
#ManoVerse Profile Picture

#ManoVerse 40

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans