Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Sample: Azure Aware Custom Workflow Activity

[Applies to: Microsoft Dynamics CRM 2011]

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

This sample code is for Microsoft Dynamics CRM 2011, and can be found in the following location in the SDK download:

SampleCode\CS\Azure\AzureAwareWorkflowActivity\Activity.cs

Requirements

You must configure Microsoft Dynamics CRM integration with Windows Azure before registering and executing this sample custom workflow activity. For more information, see Configure Windows Azure Integration with Microsoft Dynamics CRM.

Notice the “Input id” required argument in the code. When adding this activity to a workflow, you must provide the GUID of a Windows Azure service endpoint. For more information about creating a service endpoint, see Create a Service Endpoint Configuration.

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 Windows 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

Microsoft Dynamics CRM 2011
Send comments about this topic to Microsoft.
© 2013 Microsoft Corporation. All rights reserved.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.