サンプル: Azure 対応のユーザー定義ワークフロー活動

 

公開日: 2016年11月

対象: Dynamics CRM 2015

このサンプルは、現在の Microsoft Dynamics 365 の操作からデータ コンテキストを取得し、Microsoft Azure サービス バスに投稿します。

このサンプル コードは、Microsoft Dynamics CRM 2015 および Microsoft Dynamics CRM Online 2015 更新プログラム 向けです。 Microsoft Dynamics CRM SDK パッケージをダウンロードします。 このコードは、ダウンロード パッケージの次の場所にあります。

SampleCode\CS\Azure\AzureAwareWorkflowActivity\Activity.cs

要件

このユーザー定義のワークフロー活動のサンプルを登録して実行する前に、Microsoft Azure との Microsoft Dynamics 365 の接続を構成する必要があります。詳細:Azure と Microsoft Dynamics CRM 2015 との統合の構成

コードには “Input id” 引数が必要です。 この活動をワークフローに追加する場合は、Microsoft Azure サービス エンドポイントの GUID を指定する必要があります。詳細:サービス エンドポイント構成の作成

このユーザー定義のワークフロー活動を Microsoft Dynamics CRM Online に登録する場合は、サンドボックス (部分信頼) で登録する必要があります。

この SDK で提供するサンプル コードを実行するために必要な要件については、「サンプルとヘルパー コードの使用」を参照してください。

使用例

このサンプルは、現在の Microsoft Dynamics 365 操作から Microsoft Azure サービス バスにデータ コンテキストをポストできるユーザー定義のワークフロー活動の作成方法を示しています。 データ コンテキストを投稿するには、Execute メソッドを使用します。


// 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; }
    }
}

関連項目

IServiceEndpointNotificationService
Microsoft Dynamics CRM 2015 Web サービスを使用した単純なプログラムの実行
サンプル: 永続キュー リスナー
ユーザー定義ワークフロー活動 (ワークフロー アセンブリ)

© 2017 Microsoft. All rights reserved. 著作権