Chapter 24. Azure Extensions

Microsoft Dynamics CRM 2016 features improved extensibility for cloud computing and Windows Azure.

Introduction to Azure

Azure is Microsoft technology created to build and provide cloud-computing systems and applications. Hosted in the Microsoft data centers, Azure applications give end users about 99.95% uptime, and customers don’t need to invest in any infrastructure or IT services for their environment.

Azure services can be grouped into three categories: infrastructure-as-a-service (IaaS), platform-as-a-service (PaaS), and software-as-a-service (SaaS). The concept of cloud computing invites companies to alter their perspective with regard to procuring expensive on-premises equipment and hard-to-manage support and consider moving to a service-oriented service, SaaS, where they pay for the time and resources consumed (similar to what we currently do for electricity or phone services).

Azure is a set of tools and application programming interfaces (APIs) that changes the way a system or an application is designed to support the cloud-computing platform offered by Microsoft. Customers can scale the system as needed by choosing the number of servers they want to have running the same application as usage demands it (and at a low cost per month).

Azure includes the following products, which you can subscribe to separately:

Image Cloud Services

Image Data Management

Image Business Analytics

Image Identity

Image Messaging

For a complete list of the Azure products, visit https://azure.microsoft.com/en-us/regions/#services.


Note

Windows Azure is not available to purchase worldwide yet (however once purchased and provisioned, any service can be accessed worldwide). At this writing, Azure is available to purchase in 140 countries.


Service Bus Configurations

The Azure Service Bus component enables you to integrate a CRM 2016 deployment with a legacy system. Because the CRM in these scenarios is usually be the Online version, and because you cannot call external web services from plug-ins deployed on the CRM 2016 Online sandbox, you must create a Service Bus application to communicate with the external application through Service Bus.

Microsoft Dynamics CRM 2016 and Microsoft Dynamics CRM Online support integration with Windows Azure. Developers can register plug-ins with Microsoft Dynamics CRM that can pass runtime message data, known as the execution context, to one or more Windows Azure solutions in the cloud. The Windows Azure Service Bus combined with the Windows Azure Access Control Service (ACS) provide a secure communication channel for Microsoft Dynamics CRM runtime data to external line-of-business applications.

This process of using Service Bus to integrate a legacy system or application with Microsoft CRM 2016 involves the following:

Image Creating a Windows Azure Service Bus account with a subscription

Image Getting the CRM 2016 Online certificate

Image Registering a Service Bus endpoint

Image Creating a listener application

Creating a Windows Azure Service Bus Account with a Subscription

To create an Azure AppFabric Service Bus account, follow these steps:

1. Download Azure PowerShell from http://go.microsoft.com/fwlink/p/?linkid=320376&clcid=0x409 and open a new PowerShell window.

2. Run the command Add-AzureAccount to configure PowerShell to talk to the Azure account. In the dialog that appears provide your Azure subscription credentials, as shown in Figure 24.1.

Image

FIGURE 24.1 IFD Login/Verification for Azure authorization.

3. Create a new Azure Service Bus namespace by using this command:

New-AzureSBNamespace -Name "WebFortis-Crm2016" -Location "Central US"
Image-CreateACSNamespace $true -NamespaceType Messaging

but be sure to change "WebFortis-Crm2016" to the name of your organization. Figure 24.2 shows logged in PowerShell user to the Azure subscription.

Image

FIGURE 24.2 Authenticated PowerShell user.

The output shows ACSManagementEndPoint, ServiceBusEndPoint, and DefaultKey, as shown in Figure 24.3.

Image

FIGURE 24.3 PowerShell output.


Tip

Remember to make a note of the service namespace you enter here; you will need it when you register the Service Bus plug-in.


Getting the CRM 2016 Online Certificate

This book covers how to connect an application with CRM Online, which is the most appropriate scenario for this text. You can, however, connect with CRM On-Premises and in Internet-Facing Deployment (IFD) environments, but to get a certificate, you must complete the following steps, as described in the CRM 2016 software development kit (SDK):


Note

You can download the CRM 2016 SDK from http://download.microsoft.com or by searching the Microsoft site for “CRM 2016 SDK.”


1. Go to CRM Online and download the Windows Azure Service Bus Issuer Certificate by going to Settings > Customizations > Developer Resources (see Figure 24.4).

Image

FIGURE 24.4 CRM 2016 Developer Resources page.

2. Click Download Certificate under Connect This Instance of Dynamics CRM to Azure Service Bus and store the certificate on your local hard disk.

Registering a Service Bus Endpoint

To register the service bus endpoint, you use the Plug-in Registration Tool, which you can find in the CRM SDK in the SDKToolsPluginRegistration folder; the file is called PluginRegistration.exe.

Image To learn more about the Plug-in Registration Tool, which is the same one used to register any other CRM plug-in, SEE CHAPTER 25, “Plug-ins.”

Run PluginRegistration.exe and follow these steps:

1. Click Create New Connection and select Office 365 for Deployment Type and select the check box Display List of Available Organizations (see Figure 24.5). Click the Login button.

Image

FIGURE 24.5 Plug-in Registration Tool.

2. In the dialog that appears, enter the login information and click the Sign In button (see Figure 24.6). When you’re connected, you see a list of plug-ins and custom workflow activities (see Figure 24.7).

Image

FIGURE 24.6 Intranet login dialog.

Image

FIGURE 24.7 Plug-in Connection options.

3. Click Register and select Register New Service Endpoint, as shown in Figure 24.8.

Image

FIGURE 24.8 Registering a new service endpoint.

4. In the Service Endpoint Registration panel that appears (see Figure 24.9), enter a name (any name you want to use to reference your service), a description (optional), the solution namespace from the Windows Azure portal in the Service Bus section (refer to Figure 24.3), and a path (any name that you want to be part of the URL used for the endpoint).

Image

FIGURE 24.9 Service endpoint details.

The Contract drop-down can be any of these types:

Image OneWay—Used to send messages only from CRM 2016 to the service bus. For this type of contract, the listener application must be connected at the time the message is sent; otherwise, the message might be lost. If you don’t want to lose messages, you can choose the Queue contract type.

Image Queue—Specifies where the messages will be queued; this is useful for environments that are not fully connected at all times.

Image Two Way—Specifies where the messages can be sent and received from CRM 2016.

Image REST—Creates a REST (representational state transfer) endpoint that works in a two-way fashion.

Image Topic—The same as a queue, but implements the publish/subscribe model.

Image Persistent Queue—Listens for messages in Service Bus and, when available, reads the message, prints the execution context contained in the message to the console, and deletes the message from the queue.


Note

To use the Persistent Queue and Topic contracts, the listener applications must be using the Windows Azure SDK version 1.7 or 1.8.


Image To learn more about the REST protocol, refer to CHAPTER 23, “Web Services.”

5. Go to https://portal.azure.com/ and log in. After you log in, click Service Bus from the left menu options, as shown in Figure 24.10, and select the namespace and then click the Connection Information button at the bottom of the page.

Image

FIGURE 24.10 Azure Service Bus configuration.

6. In the Access Connection Information dialog that appears, copy the value from the Default Key field to the box under ACS Connection String (see Figure 24.11).

Image

FIGURE 24.11 Azure Access Connection Information.

7. Go back to the Plug-in Registration Tool and click the Save & Configure ACS button. The ACS Configuration dialog that appears, showing the default key you copied earlier under Management Key (see Figure 24.12). Find the certificate file you downloaded from CRM Online and enter its name in the Issuer Name field; it should be crm.dynamics.com for CRM Online if you are in the United States (but if you are in another country, it might be a different localized URL). The certificate file’s name will differ for On-Premises deployments.

Image

FIGURE 24.12 ACS Configuration.


Note

The keys in Figures 24.1224.14 are for example purposes and you should be sure to use your own keys (and not the ones shown).


8. Click the Configure ACS button, and when a dialog appears warning that the action cannot be undone, click Yes (see Figure 24.13). Next you see detailed process messages with their statuses. After successful configuration, the ACS Configuration dialog should look as shown in Figure 24.14.

Image

FIGURE 24.13 ACS configuration confirmation.

Image

FIGURE 24.14 ACS configuration confirming processing.

9. Click Close to close the ACS Configuration dialog.

10. Click Save & Verify Authentication in the Service Endpoint Registration dialog that appears (see Figure 24.15). The verification might take some time to complete. Upon successful verification, you should see a screen similar to Figure 24.16.

Image

FIGURE 24.15 Service Endpoint Registration dialog.

Image

FIGURE 24.16 ACS verification success.

11. Click Close to close the Verify Authentication dialog.

12. Click Save to close the Service Endpoint Details dialog. You now see the new service endpoint created in the Registered Plug-ins & Custom Workflow Activities list, as shown in Figure 24.17.

Image

FIGURE 24.17 Service endpoint created.

Now you are ready to configure the CRM events you want to listen to and have sent to Service Bus. To do that, you need to create new steps for the service endpoint you created:

1. Select the service endpoint you created, click Register, and then select Register New Step, as shown in Figure 24.18.

Image

FIGURE 24.18 Registering a new step.

2. Enter Create in the Message field and account in the Primary Entity field, as shown in Figure 24.19.

Image

FIGURE 24.19 Create message for the Account entity.

3. Click Register New Step. You should see the new step created under the ServiceEndpoint node in the Registered Plug-ins & Custom Workflow Activities list, as shown in Figure 24.20.

Image

FIGURE 24.20 New step created successfully.

Creating a Listener Application

To start receiving Service Bus messages, you need to create a listener application. To test the listener, you can create a simple console application with Microsoft Visual Studio. This example uses Visual Studio 2015. You need to have the following downloaded and installed in order to follow the example in this section:

Image WindowsAzure.ServiceBus NuGet package

Image Microsoft Dynamics CRM 2016 SDK

When you have NuGet and the SDK installed, follow these steps:

1. Right-click References and select Manage NuGet Packages, as shown in Figure 24.21.

Image

FIGURE 24.21 References > Manage NuGet Packages.

2. Select the Browse tab, type Azure in the search box, select WindowsAzure.ServiceBus version 3.0.9 or higher, and click the Install button (see Figure 24.22).

Image

FIGURE 24.22 Selecting the WindowsAzure.ServiceBus option.

References to the Microsoft.ServiceBus.dll, Microsoft.WindowsAzure.Configuration.dll, System.ServiceModel.dll, and System.Runtime.Serialization.dll files are added.

3. Add a reference to the Microsoft.Xrm.Sdk.dll assembly from the CRM 2016 Sdk/bin folder, as shown in Figure 24.23.

Image

FIGURE 24.23 Adding the reference for the AzureListener.

4. Go to the Solution Explorer, right-click the project name, and select Settings. Ensure that the target framework selected is .NET Framework 4.5.2, as shown in Figure 24.24.

Image

FIGURE 24.24 Selecting the target .NET framework from the drop-down.

After you have added all the necessary references, you are ready to insert the code. To do this, open the program.cs file and enter the following code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.ServiceBus;
using Microsoft.WindowsAzure;
using System.ServiceModel;
using System.ServiceModel.Description;
using Microsoft.Xrm.Sdk;
namespace AzureListener
{
    class Program
    {
        static void Main(string[] args)
        {
            ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Http;
            string serviceNamespace = "webfortis-crm2016";
            string issuerName = "owner";
            string issuerSecret = "321321";//Replace this with Default Key from
Connection Information from Windows Azure Portal
            // Create the service URI based on the service namespace.
            Uri address = ServiceBusEnvironment.CreateServiceUri(Uri.UriSchemeHttps,
serviceNamespace, "myService");
            Console.WriteLine("Service address: " + address);
            // Create the credentials object for the endpoint.
            TransportClientEndpointBehavior scb = new
TransportClientEndpointBehavior();
            TokenProvider = TokenProvider.
CreateSharedSecretTokenProvider(issuerName, issuerSecret);
            scb.TokenProvider = tokenProvider;
            // Create the binding object.
            WS2007HttpRelayBinding binding = new WS2007HttpRelayBinding();
            binding.Security.Mode = EndToEndSecurityMode.Transport;
            // Create the service host reading the configuration.
            ServiceHost host = new ServiceHost(typeof(RemoteServiceTest));
            host.AddServiceEndpoint(typeof(IServiceEndpointPlugin), binding,
address);
            // Create the ServiceRegistrySettings behavior for the endpoint.
            IEndpointBehavior serviceRegistrySettings = new ServiceRegistrySettings
(DiscoveryType.Public);
            // Add the Service Bus credentials to
            // all endpoints specified in configuration.
            foreach (ServiceEndpoint endpoint in host.Description.Endpoints)
            {
                endpoint.Behaviors.Add(serviceRegistrySettings);
                endpoint.Behaviors.Add(scb);
            }
            try
            {
                // Open the service.
                host.Open();
            }
            catch (TimeoutException timeout)
            {
                Console.WriteLine(timeout.Message);
            }
            Console.ReadLine();
            // Close the service.
            host.Close();
        }
    }
    [ServiceBehavior]
    class RemoteServiceTest : IServiceEndpointPlugin
    {
        public void Execute(RemoteExecutionContext context)
        {
            Entity createdDiag = (Entity)context.InputParameters["Target"];
            Console.WriteLine("Account with name = " + createdDiag.
Attributes["name"] + "was created");
        }
    }
}


Note

The solution presented here works only for a one-way contract. Additional samples in the SDK located in the sdksamplecodecsazure folder show other contract types.


Let’s review this code. For the Service Bus, you need to create a class that will implement IServiceEndpointPlugin, which has a similar interface to the one used for plug-ins (IPlugin).

Image For more information about plug-ins, SEE CHAPTER 25.

This interface forces the implementation of the Execute method. Service Bus calls this method, which sends the context parameter. This parameter contains all the information you need for the entity you registered in the service endpoint. In this case, you registered the Create message for the Account entity, so you should expect to get the Account entity instance when a new account is created.

Updating Variables for the Main Method

You need to update three variables at the beginning of the Main method with your own service information: the serviceNamespace, issuerName (Default Issue), and the issuerSecret (Default Key) variables. You can find the values of these variables in the Windows Azure portal (refer to Figure 24.11).

The Main method starts by creating the service URI (uniform resource identifier) that will connect to your service; you use myService here because that is the path you entered when you registered the service endpoint.

Then you create the credentials object that will need to be passed to the service endpoint. Notice that the credentials are created using the issuer name and the issuer secret keys. You then create the binding object, using the WS2007HttpRelayBinding class. Next, you instantiate the ServiceHost class, which is the object that will be connected to Service Bus.

Then you specify the Service class that implements the IServiceEndpointPlugin interface. Finally, you create and add the Service Bus credentials to all endpoints specified in the configuration and open the host service instance. This sample application will run until a key is pressed, and it is important to close the service host when you are done.

To test the application, press F5, and you see the console application running, as shown in Figure 24.25.

Image

FIGURE 24.25 Testing the Service Bus listener application.

Now go to the CRM web user interface, go to Accounts, and then click + New to create a new account, as shown in Figure 24.26.

Image

FIGURE 24.26 Creating a new account in CRM.

After you click Save, you see that the message is sent to the custom console application, and you also see the output, as shown in Figure 24.27.

Image

FIGURE 24.27 Account creation event received on the console application.

Azure-Hosted Dynamics CRM

Dynamics CRM hosted on Azure IaaS can leverage a number of cloud-based features. Azure IaaS virtual machines form the core building block of Azure IaaS solution. Virtual machine capabilities are determined by tiers and series. There are two tiers, basic and standard. Basic tier machines are used for test and development workloads where load balancing and auto-scaling are not required. Standard tier virtual machines are used for production environments and are divided into letter-assorted series like A, D, DS, and G.

Image You can get an Azure trial free from https://azure.microsoft.com/en-us/pricing/free-trial/.

Follow these steps to set up a basic development environment in Azure for Dynamics CRM 2016:

1. Log on to your Azure trial environment and click Virtual Machines on the left menu. Then click Create a Virtual Machine (see Figure 24.28).

Image

FIGURE 24.28 Creating a new virtual machine

2. Click From Gallery to get an existing image (see Figure 24.29).

Image

FIGURE 24.29 Selecting an existing image.

3. Select SQL Server 2014 SP1 Enterprise on Windows Server 2012 R2, click the right-arrow button in the bottom-right corner (see Figure 24.30).

Image

FIGURE 24.30 Selecting the Virtual Machine configurations.

4. In the Virtual Machine Configuration dialog that appears (see Figure 24.31), set Tier to Standard and Size to A3 (4 cores,7 GB memory). Provide any other details you’d like to add. Then click the right-arrow button in the bottom-right corner.

Image

FIGURE 24.31 Virtual Machine Configuration dialog.

5. In the new version of the Virtual Machine Configuration dialog that appears, set the Cloud Service DNS Name field and select the region where you want to host the service, as shown in Figure 24.32. Click the right-arrow button in the bottom-right corner. A virtual machine begins to be provisioned as per specifications you’ve provided.

Image

FIGURE 24.32 Virtual Machine Configuration dialog.

6. When the virtual machine status is shown as Running, click Connect at the bottom of the page and provide your login details.

7. After you log in to the virtual machine, open Server Manager and click Add Roles and Features, as shown in Figure 24.33.

Image

FIGURE 24.33 Adding roles and features.

8. In the Select Installation Type dialog that appears, select Role-Based or Feature-Based Installation and then click Next (see Figure 24.34).

Image

FIGURE 24.34 Select Installation Type dialog.

9. In the Select Destination Server dialog that appears, select Select a Server from the Server Pool and click Next (see Figure 24.35).

Image

FIGURE 24.35 Selecting the current server.

10. In the Select Server Roles dialog that appears, select Active Directory Domain Services, as shown in Figure 24.36, and then scroll down and select Windows Search Service. Click Next.

Image

FIGURE 24.36 Select Server Roles dialog.

11. When the requested roles and features are installed (see Figure 24.37), click the Close button.

Image

FIGURE 24.37 Completing the installation.

12. After the virtual machine restarts, log in to the virtual machine using the same credentials as in step 6.

13. Open the Server Manager and click Promote This Server to a Domain Controller, as shown in Figure 24.38.

Image

FIGURE 24.38 Promoting the server to a domain controller.

14. In the Active Directory Domain Services Configuration Wizard dialog that appears, select Add a New Forest, specify the root domain as WFLLC.Local, and click Next.

15. Provide the password and confirm password for Directory Services Restore Mode and click Next.

16. Click OK on the DNS server delegation warning that appears. (This setup is for a development environment, so the warning doesn’t apply to you.)

17. Verify the NetBIOS domain name and click Next.

18. Leave the default values for the AD DS database, log files, and SYSVOL folders.

19. Review your selections and click Next, as shown in Figure 24.39).

Image

FIGURE 24.39 Reviewing configured options.

20. When the prerequisite checks are passed, click OK and then Install. When the installation is completed, the server restarts automatically.

21. Log in to the virtual machine and open the Server Manager. Click Add Roles and Features.

22. Select Server Roles and then Web Server (IIS) and as well as any other necessary features shown on the next screen (see Figure 24.40).

Image

FIGURE 24.40 Selecting the Web Server (IIS) role.

23. Select Role Services on the left, beneath Application Server, and then select HTTP Activation, as shown in Figure 24.41. Make sure .NET Framework 4.5 and Web Server (IIS) Support are also selected.

Image

FIGURE 24.41 Selecting HTTP Activation.

24. Select Role Services on the left, beneath Web Server Role (IIS), and then select Management Services. Make sure other check boxes are also selected, as shown in Figure 24.42.

Image

FIGURE 24.42 Selecting Management Service.

25. Select the check box Restart the Destination Server Automatically if Required and click Install.

26. When the installation is complete, click the Close button.

27. In the Server Manager select AD DS on the left and then right-click the server in the middle frame and select Active Directory Administrative Center, as shown in Figure 24.43.

Image

FIGURE 24.43 Selecting Active Directory Administrative Center.

28. Select the domain and then go to the Users folder. Create a new user record in Active Directory that will be used to run Dynamics CRM services (see Figure 24.44).

Image

FIGURE 24.44 Creating a new user record.

29. Provide the required details and a password, making sure you select the Password Never Expires check box.

30. Click Member Of on the left side of the screen shown in Figure 24.45. Then click Add and select Performance Log Users and click OK. The user record is then added to Performance Log Users group.

Image

FIGURE 24.45 Adding the user to the Performance Log Users group.

31. Navigate to the domain folder and then create a new organizational unit to install Dynamics CRM, as shown in Figure 24.46.

Image

FIGURE 24.46 Creating a new organizational unit.

32. Name the new organizational unit CRM and click OK. Dynamics CRM will then create its AD groups here.

33. Open Reporting Services Configuration Manager and select SQL Server and click Connect.

34. Select Service Account from left menu, set Use Built-in Account to Local System, and click Apply.

35. Select Web Service URL from the left menu and click Apply (see Figure 24.47).

Image

FIGURE 24.47 Configuring SQL Server Reporting Services.

36. In the configuration wizard that appears, select Database on the left side and then select Create a New Report Server Database and click Next.

37. Provide the database server name and set Authentication Type to Current User-Integrated Security (see Figure 24.48).

Image

FIGURE 24.48 Report server configuration.

38. Enter the database name and click Next.

39. Keep Authentication Type set to Service Credentials and click Next.

40. The wizard configures the report server database. Click the Finish button to complete the setup.

41. Run Dynamics CRM Server 2016 setup. Select Get Updates for Microsoft Dynamics CRM and click Next.

42. Provide the product key for your Dynamics CRM instance (either the free trial key or from your MSDN subscription) and click Next.

43. Select the check box I Accept This License Agreement and click I Accept.

44. On the next screen, click Install to install any missing required components.

45. Select the installation directory and click Next (see Figure 24.49).

Image

FIGURE 24.49 Selecting the installation location for the CRM server.

46. Select all the server roles, as you are doing an installation of a single server only which by definition has all the roles on the single server, and click Next (see Figure 24.50).

Image

FIGURE 24.50 Selecting server roles for installation.

47. Select the option Create a New Deployment, provide the name of the server running SQL Server, and click Next.

48. Click Browse and select the CRM organization unit created earlier (see Figure 24.51).

Image

FIGURE 24.51 Selecting the CRM organization unit.

49. Provide the credentials of the user account created earlier and click Next.

50. Select Create New Website and provide the port number, in this case 5555. (There might be some other applications running under default port 80 in the future, but because this is a new server, you could use port 80 if desired.) Click Next.

51. Skip the email router settings and just click Next.

52. Provide a display name for the organization and select the base currency and click Next (see Figure 24.52).

Image

FIGURE 24.52 Selecting the currency and display name.

53. Specify the report server URL. You can copy paste the prepopulated URL for the report server to test (see Figure 24.53). Click Next.

Image

FIGURE 24.53 Configuring the report server.

54. Click the Install button to begin the Dynamics CRM server installation.

55. When the installation is complete, click View the Log File to see if there are any errors. Ensure that the Restart the Computer When the Wizard Closes check box and click Finish to restart the server.

56. Go to Dynamics CRM setup and open the SrsDataConnector folder. Run SetupSrsDataConnector.exe to install Reporting Extensions (see Figure 24.54).

Image

FIGURE 24.54 Navigating to the SrsDataConnector executable.

57. Specify where the configuration database for Dynamics CRM is installed and click Next.

58. Select the SSRS instance name that is used for Dynamics CRM reporting and click Next.

59. Specify the installation directory and click Next.

60. When the verification checks are complete, if there are no errors, click Next.

61. Review your selections and click Install.

62. Click View the Log File to see if there are any errors and then click Finish.

63. Open your browser and go to http://<server>:<portname>/ to open Dynamics CRM, as shown in Figure 24.55.

Image

FIGURE 24.55 Dynamics CRM running on port 5555.

Azure ExpressRoute

You can create private connections between infrastructures that are in an On-Premises or Online environment and Azure data centers using by Azure ExpressRoute. ExpressRoute provides more reliability, faster speed, higher throughput, lower latency, and an extra level of protection by not relying on the public Internet to route traffic. With ExpressRoute you get your own private connection to Azure, and Azure acts likes your private cloud.

Azure ExpressRoute is now available for Dynamics CRM online customers.


Note

For more information about the ExpressRoute offerings, go to https://azure.microsoft.com/en-us/services/expressroute/.


Summary

In this chapter you have seen how to use the Microsoft Windows Azure platform to interact with Microsoft Dynamics CRM entity events through Service Bus. In addition, you’ve seen the process required to register a new Service Bus and the sample code and components necessary to listen to these messages.

Finally, this chapter covers hosting Dynamics CRM on an Azure environment and Azure ExpressRoute.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset