इसके माध्यम से साझा किया गया


Sample: Azure aware custom workflow activity

 

Applies To: Dynamics 365 (online), Dynamics 365 (on-premises), Dynamics CRM 2016, Dynamics CRM Online

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

This sample code is for Microsoft Dynamics 365 (online & on-premises).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 365 to connect with Microsoft Azure before registering and executing this sample custom workflow activity. More information: Configure Azure integration with Microsoft Dynamics 365.

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: Create a service endpoint configuration.

When registering this custom workflow activity with Microsoft Dynamics 365 (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 365 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 365 and Microsoft Azure integration
Sample: Persistent queue listener
Custom workflow activities (workflow assemblies)

Microsoft Dynamics 365

© 2016 Microsoft. All rights reserved. Copyright