Hello,
Unable to connect to Dynamics CRM from Azure Web Jobs.
< addname="CRM"connectionString="Url=https://pocenv.crm.dynamics.com;Username=lastname.firstname@corp.edu;Password=pass@wd"/>
Following is the simple code being used.
private
staticstringCRMConnectionString = ConfigurationManager.ConnectionStrings["CRM"].ConnectionString;
private
staticCrmConnectioncrmConnection;
privatestaticOrganizationServiceorgService;
crmConnection =
CrmConnection.Parse(CRMConnectionString);
orgService =
newOrganizationService(crmConnection);
GuidentityId =newGuid(Id);
Entityentity=newEntity("poc_entity");
entity.Id = entityId;
entity.Attributes["statuscode"] = new OptionSetValue(853970004);
orgService.Update(entity);
this code always results in Failure with following Exception thrown in the web job.
Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: ExperimentDriver.ProcessRequest ---> System.AggregateException: One or more errors occurred. ---> System.ServiceModel.FaultException: MSIS7068: Access denied.
at System.ServiceModel.Security.WSTrustChannel.ReadResponse(Message response)
at System.ServiceModel.Security.WSTrustChannel.Issue(RequestSecurityToken rst, RequestSecurityTokenResponse& rstr)
at Microsoft.Xrm.Sdk.Client.ServiceConfiguration`1.Issue(AuthenticationCredentials authenticationCredentials)
at Microsoft.Xrm.Sdk.Client.ServiceConfiguration`1.AuthenticateInternal(AuthenticationCredentials authenticationCredentials)
at Microsoft.Xrm.Sdk.Client.ServiceConfiguration`1.AuthenticateWithADFSForOrgId(AuthenticationCredentials authenticationCredentials, Uri identifier)
at Microsoft.Xrm.Sdk.Client.ServiceConfiguration`1.AuthenticateOnlineFederationInternal(AuthenticationCredentials authenticationCredentials)
at Microsoft.Xrm.Sdk.Client.ServiceConfiguration`1.Authenticate(AuthenticationCredentials authenticationCredentials)
at Microsoft.Xrm.Sdk.Client.ServiceConfiguration`1.Authenticate(ClientCredentials clientCredentials)
at Microsoft.Xrm.Sdk.Client.OrganizationServiceConfiguration.Authenticate(ClientCredentials clientCredentials)
at Microsoft.Xrm.Client.Services.OrganizationService.CreateUserTokenResponse(CrmConnection connection, IServiceConfiguration`1 config)
at Microsoft.Xrm.Client.Services.OrganizationService.GetUserTokenResponse(CrmConnection connection, IServiceConfiguration`1 config)
at Microsoft.Xrm.Client.Services.OrganizationService.ToOrganizationServiceProxy(CrmConnection connection)
at Microsoft.Xrm.Client.Services.OrganizationService.ToOrganizationService(CrmConnection connection)
at Microsoft.Xrm.Client.Services.OrganizationService.<>c__DisplayClass2.<.ctor>b__0()
at System.Lazy`1.CreateValue()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Lazy`1.get_Value()
at Microsoft.Xrm.Client.Services.OrganizationService.InnerOrganizationService.UsingService(Action`1 action)
at Microsoft.Xrm.Client.Services.OrganizationService.Update(Entity entity)
at ExperimentDriver.ExperimentDriver.UpdateStatusInCRM(String Id, String statusMsg, TextWriter log)
at ExperimentDriver.ExperimentDriver.<ExecuteExperiment>d__16.MoveNext()
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at ExperimentDriver.ExperimentDriver.ProcessRequest(BrokeredMessage brokeredMessage, TextWriter log)
at lambda_method(Closure , ExperimentDriver , Object[] )
at Microsoft.Azure.WebJobs.Host.Executors.VoidMethodInvoker`1.InvokeAsync(TReflected instance, Object[] arguments)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`1.<InvokeAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<ExecuteWithWatchersAsync>d__31.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<ExecuteWithLoggingAsync>d__2c.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<ExecuteWithLoggingAsync>d__13.MoveNext()
--- End of inner exception stack trace ---
Please Advise. We have Express Route Setup with customers network & Azure. CRM Online is also in customers tenant.
Alok