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