Share via


Sample: Azure aware custom workflow activity

 

Applies To: Dynamics CRM 2015

This sample obtains the data context from the current Microsoft Dynamics CRM operation and posts it to the Microsoft Azure Service Bus.

This sample code is for Microsoft Dynamics CRM 2015 and Microsoft Dynamics CRM Online 2015 Update. Download the Microsoft Dynamics CRM SDK package.  This code can be found in the following location in the download package:

SampleCode\CS\Azure\AzureAwareWorkflowActivity\Activity.cs

Requirements

You must configure Microsoft Dynamics CRM to connect with Microsoft Azure before registering and executing this sample custom workflow activity. More information: Configure Azure integration with Microsoft Dynamics CRM.

Notice the “Input id” required argument in the code. When you add this activity to a workflow, you must provide the GUID of a Microsoft Azure service endpoint. More information: adc9af13-8505-4701-ab74-064df1f346a0#BKMK_Create.

When registering this custom workflow activity with Microsoft Dynamics CRM Online, you must register it in the sandbox (partial trust).

For more information about the requirements for running the sample code provided in this SDK, see Use the sample and helper code.

Demonstrates

This sample shows how to write a custom workflow activity that can post the data context from the current Microsoft Dynamics CRM operation to the Microsoft Azure Service Bus. The posting of the data context is done through the Execute method.

Example


// This namespace is found in the System.Activities.dll assembly.
using System.Activities;

// This namespace is found in the Microsoft.Xrm.Sdk.dll assembly
// located in the SDK\bin folder of the SDK download.
using Microsoft.Xrm.Sdk;

// This namespace is found in the Microsoft.Xrm.Sdk.Workflow.dll assembly
// located in the SDK\bin folder of the SDK download.
using Microsoft.Xrm.Sdk.Workflow;

namespace Microsoft.Crm.Sdk.Samples
{
    /// <summary>
    /// This class is able to post the execution context to the Windows Azure 
    /// Service Bus.
    /// </summary>
    public class AzureAwareWorkflowActivity : CodeActivity
    {
        /// <summary>
        /// This method is called when the workflow executes.
        /// </summary>
        /// <param name="executionContext">The data for the event triggering
        /// the workflow.</param>
        protected override void Execute(CodeActivityContext executionContext)
        {
            IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();

            IServiceEndpointNotificationService endpointService =
                     executionContext.GetExtension<IServiceEndpointNotificationService>();
            endpointService.Execute(ServiceEndpoint.Get(executionContext), context);
        }

        /// <summary>
        /// Enables the service endpoint to be provided when this activity is added as a 
        /// step in a workflow.
        /// </summary>
        [RequiredArgument]
        [ReferenceTarget("serviceendpoint")]
        [Input("Input id")]
        public InArgument<EntityReference> ServiceEndpoint { get; set; }
    }
}

See Also

IServiceEndpointNotificationService
Sample code for Microsoft Dynamics CRM and Microsoft Azure integration
Sample: Persistent queue listener
Custom workflow activities (workflow assemblies)

© 2016 Microsoft. All rights reserved. Copyright