While Dynamics 365 Plug-ins allow declarative integration with Azure Service Bus via ServiceEndPoints, integrating through Custom Workflow Activity requires some coding.
So why would you prefer a Custom Workflow Activity over a Plug-in?
Here are just a few good reasons:
- Cost-efficiency: A Custom Workflow Activity component can be embedded in Custom Actions, A/Sync. Workflow, Dialog (while it’s still here), while Plug-in component can only be called and operate via the Plug-in execution context. When you put time into writing code, you want to allow as much re-use as possible.
- Declarative: once registered, Custom Workflow Activity can be leveraged by non-developers in various Processes, while Plug-in is usually accessible only to developers.
- Ubiquity: A Custom Action wrapping a Custom Workflow Activity can be accessed from other processes, client side code, server side code and consumers external to Dynamics 365
- Flexibility: unlike the built in declarative integration, addressing Azure Service Bus via code allows you to add conditional logic and also reduce the message payload (see component code).
Convinced or not, the following walkthrough demonstrates using the Post Message To Azure Service Bus Custom Workflow Activity component to post message to ASB queue.
You can view the source code here and modify as required.
Prerequisites:
- Azure subscription allowing you to provision Azure Service Bus
- Microsoft Dynamics 365 9.x instance with admin privileges, a trial will do
- Access to Plugin Registration Tool
Walkthrough:
- Setup Azure Service Bus and make a note of the connection string
- Use the Plugin Registration Tool to register a ServiceEndPoint and the noted connection string
- Download, import and publish the unmanaged solution available here
- Configure the solution contained Workflow by selecting the registered ServiceEndPoint, stating semi-column delimited properties list and an optional custom message. Activate the Workflow Rule.
- Test by manually activating the Workflow on a Contact record.
If all goes well, a new message will appear in ASB queue. You can view the queue dashboard in Azure Portal.
If you want to view the actual message content, you can use Azure Service Bus Explorer
Few implementation notes:
- While the IWorkflowContext allows accessing the target record properties via Pre/Post entity images, this technique is not documented and therefor considered unsupported.
For this reason, the code explicitly retrieves and push the required attributes values into the SharedVariables collection.
The propertiesSet input parameter allows sending in a list of required properties. - Clearing the IWorkflowContext data heavy collections before posting it to Azure Service Bus can reduce the the message payload weight by ~80%, which can simplify handling the message and improve performance.