In this blog we go through a step by step tutorial to setup a CRM-Azure Service Bus one way listener contract using ACS.
- A CRM Online instance
- Microsoft Azure account
- Microsoft Azure SDK
- Visual Studio 2013/2015
- CRM2016 SDK V8.0.1 or less ( We will be using the plugin registration tool and sample code from the SDK. The plugin registration tool does not have ACS options from SDK v8.1 onwards)
Setting up a Service Bus NamespaceThe first thing you need for the integration is a Service Bus namespace. If you already have an ACS namespace, you can skip this step.
In the past you could login to the Azure portal and create an ACS namespace. But now, Azure portal does not allow the creation of ACS namespaces from the portal. It only creates a SAS namespace by default. We need to use PowerShell to create an ACS namespace.
- Open “Windows PowerShell ISE”
- Type Add-AzureAccount. It will open the login dialog. Enter the username and password for your Azure account and press login.If everything goes smoothly, the PowerShell output will look like the following screenshot.
- Type the following command below to create a Service Bus namespace. Replace ‘MSCRMShopBus’ with the namespace you want and press enter
New-AzureSBNamespace -Name "MSCRMShopBus" -Location "Australia East" -CreateACSNamespace $true -NamespaceType Messaging. Replace the parameters values as required.
- The output screen will look like the following screenshot. It will create a namespaces for both ACS and SAS.
- This step is optional. Login to your Azure account and check the connection information of the Service Bus namespace. It will look like the following screen.
Get the Certificate file and Issuer name for CRMFor CRM Online
To get the security certificate and the issuer name for CRM go to Settings>>Customizations>>Developer Resources. Download the certificate file and also notice the issuer name of the certificate.
For CRM On Premise
For CRM on premise, follow the following article for step by step instructions.
Setting up the CRM Service EndpointHere are the steps
- Start the plugin registration tool. It is available in the \SDK\Tools location of the SDK. I am using SDK v1.8.
- Click on Register>>Register New Service Endpoint
- It will open the the following page. Enter the Values as required and press “ Save & Configure ACS”.
Solution Name is the Service Bus namespace we created in the beginning of this blog.
Path is the path of your listener project. For example, when you run the listener project for a one-way listener for this blog, the service endpoint URL will look like https://mscrmshopbus.servicebus.windows.net/RemoteService
Contract is the type of contract we are using for the service endpoint. For the difference types of contracts check the last blog.
Setting up a listener application
- For this blog, I am using the Azure sample code that comes with the CRM SDK. Open the “OnewayListener” project from the location \SDK\SampleCode\CS\Azure\OneWayListener.
- Resolve the missing references. The 2 highlighted DLLs are available in the Azure SDK.
- Run the sample code. It will prompt for the following information.
Service Namespace is the Service Bus namespace.
Issuer name is the “Default Issuer” on the Service Bus connection information as shown in the step 5 of “Setting up a service bus namespace”. It is not the issuer name in CRM Online.
Issuer Secret is the “Default Key” on the Service Bus connection information.
- If everything is working properly it will display the service address as shown in the screenshot of step 3.
Testing the integration
- The listener application should be up and running.
- Login to CRM and create a new account. If everything is working properly, it will display the data context in the listener application.
- To check the status of the jobs you can go to the “System Jobs” view.
- If the listener application is not available, the status of the job will change to “Waiting for Retry”. It will keep trying to post the message and ultimately change to “failed” if it is not successful after X number of tries. The screenshot below display the details of the job with the status “waiting for retry”.