-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAzureFunctionSampleCodeForCEIntegration
More file actions
63 lines (51 loc) · 2.06 KB
/
AzureFunctionSampleCodeForCEIntegration
File metadata and controls
63 lines (51 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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 )
{
Entity customEntity = new Entity("ecellors");
customEntity["name"] = "Created from the azure function app";
service.Create(customEntity);
}
return Task.CompletedTask;
}
private static IOrganizationService Connection(TraceWriter log) {
IOrganizationService service = null;
#region Credentials Code
//Credentials
string URL = "Dynamics CRM URL";
string userName = "userName";
string password = "passWord";
#endregion
string conn = $ @ "Url = {URL};AuthType = {AuthType};UserName = {userName};Password = {password}; AppId=0b065231-6d28-431e-ab12-4d7d3346612c; RedirectUri=app://singaporecancersociety.crm5.dynamics.com/ LoginPrompt=Never" />
var svc = new CrmServiceClient(conn);
service = svc.OrganizationWebProxyClient != null ? svc.OrganizationWebProxyClient : (IOrganizationService) svc.OrganizationServiceProxy;
if (service != null) {
Guid userid = ((WhoAmIResponse) service.Execute(new WhoAmIRequest())).UserId;
if (userid != Guid.Empty) {
log.Info("Connection Established Successfully...");
}
} else {
log.Info("Failed to Established Connection!!!");
}
} catch (Exception ex) {
log.Info("Exception caught - " + ex.Message);
}
return service;
}
}