Month: November 2017

Dynamics CRM and Azure Service Bus Queues Messaging over the cloud

Dynamics CRM and Azure service bus integration Part 4

Install the CRM Endpoint Service

The fourth and final part of the CRM Connector blog details how to install and configure the CRM Endpoint service to listen for messages sent via the Azure service bus queue.  The endpoint service is a compact windows service that registers its interest on messages placed on the Azure service bus queue.  Whenever a message arrives we take the message and places it on a local queue (by default MSMQ) for further processing.

The destination queue is defined in the plugin configuration <endpoint> element.  The endpoint service reads this entry from the queue and places the resulting output from the FetchXML onto this queue for processing by your backend.


I wont go into to much detail on the installation of the service as its just a standard windows installation.  However there are a couple of configuration options in the app.config that bear discussion.

We need to set the OwinService.ASBEndpoint to the confguration created in part1

 <add key="OwinService.ASBEndpoint" value="Endpoint=sb://;SharedAccessKeyName=ReadWriteToQueue;SharedAccessKey=V8j7VPqA.../Hc=;EntityPath=crm365queue" />

After running the service and pushing a messages onto the queue, we see something xml like

<xml version="1.0">
<GenericMessage xmlns:xsi="" xmlns:xsd="" xmlns="">
 <Message>{"__contract":"update_customeraddress_bad5c2bf-6dd3-4f7e-aef7-474658982395","operation":"Update","columns":["city","postalcode","line1","line2","line3","county","fort_pin","fort_name"],"entity":"customeraddress","id":"bad5c2bf-6dd3-4f7e-aef7-474658982395","county":"UNITED KINDGOM","createdby":"efde08b0-26e3-4ac3-818b-84fb808b12db","createdby_formatted":"Robert Hawkins","line3":"EAST MIDLANDS","postalcode":"PE20 3EA","fort_registrant.fort_name":"2017A0001 / 2004","fort_registrant.fort_pin":"2017A0001","line1":"8 WITNEY WAY","line2":"KIRTON"}</message>;

if we extract the message node its just the JSON representation of the FetchXML result

 "county":"UNITED KINDGOM",
 "line3":"EAST MIDLANDS",
 "postalcode":"PE20 3EA",
 "fort_registrant.fort_name":"2017A0001 / 2004",
 "line1":"8 WITNEY WAY",

The columns element represents the output columns of the FetchXML, this is necessary because by default FetchXML does not output empty nodes.
The problem with this is if we request data thats null or empty in CRM we do not get an empty results node. In the example above we requested
column [City] but there is no corresponding { “city” : ??? } in the result as this entity has a null or empty [City].

Dynamics CRM and Azure Service Bus Queues Messaging over the cloud

Dynamics CRM and Azure service bus integration Part 3

Install the CRM To Bus plugin

Part 3 or our blog series details how to install and configure our plugin to react to a ‘customeraddress’ entity update and send the customer address along with the ‘fort_registrant’ entity values, PIN and Name.

  1. Install the Fortesium CRM-Connector CrmToBusPlugin.  The plugin exposes two entry points, a HttpServiceHost which uses the HTTP transport and the AzureServiceBusHost which utilises the Azure service bus transport. For this post we are only concerned with messaging via the ServiceBusHost.
  2. After installation register a new step, as you would any other plugin.   The plugin step takes its configuration from a fetchxml statement.
  3. The plugin unsecure configuration takes the following XML format.  The <fetch> was taken from a fetchxml statement, built using the excellent FetchXml Builder plugin for the XRMToolbox
      <entity name="customeraddress" >
        <filter type="and" >
          <condition attribute="customeraddressid" operator="eq" value="{0}" />
        <attribute name="city" />
        <attribute name="postalcode" />
        <attribute name="line1" />
        <attribute name="line2" />
        <attribute name="line3" />
        <attribute name="modifiedby" />
        <attribute name="createdby" />
        <attribute name="modifiedon" />
        <attribute name="createdon" />
        <link-entity name="fort_registrant" from="fort_registrantcontact" to="parentid" alias="fort_registrant">
          <attribute name="fort_pin" />
          <attribute name="fort_name" />
  4. The service point id ‘ebe54d31-b5c3-e711-8107-e0071b7fe041‘ can be found here
  5. The endpoint is the destination of the address for the message.  For example to send the query results of the fetch-xml to a MSMQ queue called ‘FMS-CRM-QUEUE’ on host ‘FortesiumAppServer’ the endpoint ‘FMS-CRM-QUEUE@FortesiumAppServer‘ is used.
  6. The filter condition, value ‘{0}’ is the current entity primary identifier
          <condition attribute="customeraddressid" operator="eq" value="{0}" /> 
          <!-- is the same as -->
          <condition attribute="customeraddressid" operator="eq" value="c1668630-0676-e711-80ff-70106faa6a31" />

Dynamics CRM and Azure Service Bus Queues Messaging over the cloud

Dynamics CRM and Azure service bus integration Part 2

How to register the service bus queue in the plugin registration tool

Following on from our series of posts showing how you can use the Dynamics CRM-Connector, this post details how you register a service bus queue in the  plugin registration tool.

Download and install the Microsoft Dynamics 365 Software Development Kit, open up the plugin registration tool and connect to your organisation.

  1. Click Register -> Register New Service Endpoint
  2. Choose connection string and paste the Primary Connection String from the SAS policy created earlier

  3. After clicking next – you should see the full connection details, click [Save] to continue
  4. To receive messages sent across the service bus the CRM-Connecter requires a service endpoint id.  To generate a service endpoint id, register a new step against the service endpoint.  The actual parameters supplied in the registration are not important; we just require the service endpoint id that gets generated.
  5. After a new step has been registered a new service point id will have been created.   We will use this id in the configuration of the Fortesium CRM-Connector plugin.

Dynamics CRM and Azure Service Bus Queues Messaging over the cloud

Dynamics CRM and Azure service bus integration Part 1

How to create a service bus in Azure


Many of our customers host their own Microsoft Dynamics CRM (now more formally known as Dynamics 365) applications but also need the advantages of the FMS system.  As more and more enterprises move to the cloud we needed an effective way of communicating across the boundaries of on-premise and off-premise installations.

Business applications constantly change and evolve; as such our integration solution also has to change and evolve. We needed the flexibility of a configuration based solution combined with the reliability required for business apps to function.  What we eventually came up with was the Dynamics CRM Connector for FMS.

Dynamics CRM-Connector for FMS

The Dynamics CRM-Connector for FMS – (let’s call it the the CRM-Connector), allows an off-premise or on-premise CRM installation to send and receive business information to and from FMS.  (in fact any configured application can benefit from the connector) – contact us now to find out how you can benefit.   By using the functionality of CRM FetchXML combined with the reliability of the Azure service bus message queues, we created a generic solution allowing raised CRM events ‘create’, ‘update’, ‘delete’ etc to invoke your FetchXML sending the results over the cloud to your on-premise or off-premise back ends.

  • The Dynamics CRM Connector solves the following scenarios

“A new contact has been created and you want a backend service to respond to this event. Your not actually interested in the all contact entity details, you just want the {contact entity address} and for the sake of this discussion a {credit card number from a custom payment entity}. Note that the backend service has no direct connection to your CRM instance.”

To accomplish this create an Azure service bus message queue, install the CRM-Connector plugin and finally use the Fortesium CRM-Connecter service to read messages of the queue and place it anywhere on your infrastructure.  All that is now needed is to write to some custom FetchXML for the plugin that will be invoked when a contact is created.

For example

  <entity name="customeraddress" >
    <filter type="and" >
      <condition attribute="addresstypecode" operator="eq" value="453670000" />
    <attribute name="city" />
    <attribute name="postalcode" />
    <attribute name="line1" />
    <attribute name="line2" />
    <attribute name="line3" />

    <link-entity name="fort_payment" from="fort_paymentcontact" to="parentid" alias="fort_payment">
      <attribute name="fort_visacardnumber" />

With this in place every time a new contact is created in CRM your app can receive the {contact address} and the {payment card no}.  If you need more data, no coding is required – just update the FetchXml.

This sequence of blog posts shows how you can install and run the CRM-Connector.

Create a service bus in Azure

The steps may look complex but in actual fact its all very simple and straightforward.  To begin let’s create a service bus in Azure, add a queue and garner the information needed to connect to it.

  1. Navigate to Azure portal with your credentials, Click [+ New] and search for [Service Bus]
  2. On the result page choose Service Bus and click [Create], a new blade will pop up – complete the required information and create the service bus.
  3. Wait until the deployment completes (it can take 2 or 3 minutes)
  4. Now we have our service bus , we need to create a queue that we can use for communication to and from the CRM-Connector. To create a new queue, find the resource in the dashboard and click [+ Queue]
  5. On the queue creation blade enter the name of your queue
  6. After the queue has been created, Click on the queue from the list to open the Queue details blade.
  7. We need to generate an access key (SAS Access key) for this queue so that we can provide the connection details to other applications (like CRM) to communicate.  Read more about it over here. Click on the Shared Access Policies [+ Add]

  8. Give policy name some thing relevant to you and provide only “Send” and “Listen” permissions to the queue.  I am not giving “Manage” access to any one.
  9. Clicking on the new policy will show the policy details.  We will need this information in the next section when configuring the CRM plugin.