Sample: Azure aware custom workflow activity

 

Applies To: Dynamics CRM 2013

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

This sample code is for Microsoft Dynamics CRM 2013 and Microsoft Dynamics CRM Online.  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 integration with Microsoft Azure before registering and executing this sample custom workflow activity. More information: Configure Microsoft Azure integration with Microsoft Dynamics CRM 2013.

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. For more information about creating a service endpoint, see No text is specified for bookmark or legacy link 'adc9af13-8505-4701-ab74-064df1f346a0#bkmk_createEndpoint'..

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 2013 and Microsoft Azure integration
Sample: Queue listener
Custom workflow activities (workflow assemblies)