Connect Ms Crm to Azure Function through visual Studio 2019 version
Connect MS Crm to Azure Function through visual Studio 2019 version
By connecting Crm to azure function we call the function through any web api.
Step1: Add the azure development to visual studio through your installer of vs.
Step2: Select the new project and search for the azure functions
Step3: Give the name of function and location and select the create
Step4: Select the .NET framework and trigger as http trigger.
by default it will come one function and some errors. these errors will be disappear after few minutes.
From this stage onwards out connection to Crm is Started.
We need to clear the Below code in function and replace the below code
add these refrecne to your project from Sdk File
1.Microsoft.CrmSdk.CoreAssemblies
2.using Microsoft.Xrm.Sdk
3.using Microsoft.Xrm.Tooling.Connector
These rerecne need to add from the sdk file. at that time only it will work.
Code to connect Crm
C# Code
using System.Linq;
using System.Net;
using System.Net.Http;
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.Tooling.Connector;
namespace FunctionApp3
{
public static class Function1
{
static string Url = "https://Environmenturl/main.aspx";
static string Username = "Username ";
static string Password = "Password";
static string connectionstring = $@" AuthType=OAuth;Url={Url};UserName={Username};Password={Password};
AppId=Appidfromcrm;Redirecturi= http://localhost;LoginPrompt=Auto;RequireNewInstance=True";
[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.");
// create crmservice client
CrmServiceClient Coone = new CrmServiceClient(connectionstring);
{
if (Coone.IsReady)
{
WhoAmIResponse response =
(WhoAmIResponse)Coone.Execute(new WhoAmIRequest());
IOrganizationService service = (IOrganizationService)Coone.OrganizationWebProxyClient != null ? Coone.OrganizationWebProxyClient : (IOrganizationService)Coone.OrganizationServiceProxy;
// Iam creating New record to crm
Entity contacrs = new Entity("contact");
contacrs["lastname"] = "fromfunction";
service.Create(contacrs);
}
}
//retruning the task
return Task.CompletedTask;
}
}
}
After Writting this code Execute the code and copy the url
After copying the url we need to call that url from the Postman or anyother webapi apps.
Open the postman and select the Post method and paste the url in that
After selecting and adding the url then click on send.
Then we will get the 200 repsonse and go and check the created record in your Crm.
where will call the postman ...
ReplyDeletePostman is used to conusme the Ms crm by using azure.. By using postman we can crud operations on crm
ReplyDelete