2016-07-11 9 views
1

Ich habe einen benutzerdefinierten Workflow-Schritt gemacht, die E-Mail an die Gruppe von Benutzern sendet. Ich nehme precreated E-Mail und senden Sie es programmatisch:Benutzerdefinierte Workflow-Schritt inkonsistentes Verhalten

if (recepients.Entities.Any()) 
    { 
     Entity email = service.Retrieve("email", mailId, new ColumnSet(true)); 

     email.Attributes["to"] = recepients.Entities.ToArray(); 

     service.Update(email); 

     SendEmailRequest sendEmail = new SendEmailRequest() 
     { 
      EmailId = mailId, 
      IssueSend = true 
     }; 

     service.Execute(sendEmail); 
    } 

Das Problem ist - es im Sync-Modus funktioniert gut, und werfen eine „Invalid Cast“ Ausnahme, wenn ich Workflow in async umwandeln und versuchen, sie auszuführen.

Hier welche Trace-Protokoll auf dem Server bietet:

>System.InvalidCastException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #EBCA9EC1: System.InvalidCastException: Specified cast is not valid. 

> at Microsoft.Crm.Common.ObjectModel.TrackingManager.GetNextTrackingToken(String subject, String& trackingToken) 

> at Microsoft.Crm.Common.ObjectModel.EmailService.Send(Guid emailId, Boolean issueSend, String trackingToken, ExecutionContext context) 

Irgendwie Fehler während der Umwandlung Ergebnisse des Workflows. Wo soll ich nach der Wurzel dieses Problems suchen?

 at WorkflowToAsyncResultConverter.Convert(WorkflowSystemPausedResult wfResult) ilOffset = 0x23 
     at WorkflowToAsyncResultConverter.Convert() ilOffset = 0x9D 

     at WorkflowContext.EndProcessing(IGenericHandlerResult result) ilOffset = 0xC 

     at ActivityHost.CompleteWorkflow(IGenericHandlerResult result, WorkflowApplication activityInstance, ICommonWorkflowContext context) ilOffset = 0x70 

     at ActivityHostBase.OnWorkflowTerminated(WorkflowApplicationUnhandledExceptionEventArgs args, WorkflowApplication activityInstance, ICommonWorkflowContext context) ilOffset = 0x8F 

     at UnhandledExceptionEventHandler.OnStage1Complete(IAsyncResult lastResult, WorkflowApplication instance, Exception exception, Activity source, String sourceInstanceId) ilOffset = 0x46 

     at UnhandledExceptionEventHandler.Run(WorkflowApplication instance, Exception exception, Activity exceptionSource, String exceptionSourceInstanceId) ilOffset = 0x78 

     at WorkflowApplication.OnNotifyUnhandledException(Exception exception, Activity exceptionSource, String exceptionSourceInstanceId) ilOffset = 0x23 

     at ActivityExecutor.NotifyUnhandledException(Exception exception, ActivityInstance source) ilOffset = 0x18 

     at Scheduler.OnScheduledWork(Object state) ilOffset = 0x123 

     at SendOrPostThunk.UnhandledExceptionFrame(Object state) ilOffset = 0x0 

     at ScheduledOverlapped.IOCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped) ilOffset = 0x22 

     at IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped) ilOffset = 0x5 

     at _IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP) ilOffset = 0x3C 
+0

Wie bekommen Sie den Service in Ihr eigener Workflow-Schritt? Wird es im Kontext des ausführenden Benutzers ausgeführt? –

+0

@Henrik Ich bekomme einen Factory-Out-of-Execution-Kontext und erstelle dann eine Instanz von OrganizationService mit SYSTEM-Rechten. – user3032348

Antwort

1

Versuchen Sie, eine OrganizationService läuft als ausführende Benutzer, statt SYSTEM zu schaffen. Ein ähnliches Problem mit dem Kern E-Mail-Betrieb wurde von Andrii Butenko, who concluded that it works when running the service in the context of the executing user.

Ich habe mich verändert Instanziierung Dienst läuft Benutzer und alles funktionierte ohne Probleme erfahren worden:

IOrganizationServiceFactory factory = 
    (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); 
IOrganizationService service = factory.CreateOrganizationService(executioncontext.UserId); 
+0

Vielen Dank! Jetzt funktioniert es. – user3032348