Sunday, June 14, 2015

BizTalk Server & Dynamics CRM Online: Integration with On-premises Lines of Business Systems Using BizTalk Server 2013

This is the eighth blog post in this series.  You can find the previous posts here:
Companies that leverage Dynamics CRM Online want to take full advantage of its rich set of capabilities by integrating with existing lines of business systems that are available on premise. It is common nowadays for organizations to have other lines of business systems that are hosted on premise, behind the firewall.
In this initial blog, I will show one solution that is available for integrating CRM Online with BizTalk 2013 hosted on premise. In the first scenario, I will demonstrate how data can be sent from the BizTalk application to CRM Online.

BizTalk to CRM Online Integration
1
Fig. 1: Overall Architecture of main components
CRM Online exposes the Organization Service (IOrganizationService). This is a built-in CRM WCF service that is used to interact with CRM data and metadata.
I will be simulating creating a new account via BizTalk and show how to send it to CRM Online. In order to run this scenario, you will need the following:
  • CRM Online account
  • CRM SDK
  • BizTalk Server 2013

Summary of steps (additional details and screenshots below):

  1. Navigate to the CRM online organization instance to retrieve the OrganziationService URL.
  2. Use BizTalk WCF Service Consuming wizard to generate schema from the Organization Service web service.
  3. Create source schema (Account schema).
  4. Map source schema to the CRM online schema generated in step 2.
  5. Create orchestration (CreateAccount orchestration).
  6. Create custom binding and behavior; register them in BizTalk.
  7. Configure WCF custom send port.
  8. Configure BizTalk.
  9. Simulate sending message by dropping the account sample file in the predefined folder.
  10. Log into CRM Online and verify that the account has been created.

Using Organization Service to interact with CRM Online Walkthrough:

Step 1 – Log into CRM Online to retrieve Organization Service URL;
Go to Settings – > Customizations -> Developer Resources
2

Step 2 – Use BizTalk Publish Wizard to generate the schema and the binding file.
In BizTalk solution right-click schema project, select Add and then Add Generated Items; selectConsume WCF Service Wizard; navigate through the wizard and enter the URL of your Dynamics Organization Service endpoint ( the url discovered in Step1); after clicking the Get button, click ‘Next’ and select Import.
3
Step 3 – Replace the generated Organization Service schema with the BizTalk schemas that are provided via CRM SDK (\SDK\Schemas\CRMBizTalkIntegration)
4
Below is the organizationservice_schemas_microsoft_com_xrm_2011_contracts_services schema. Note that the schema provides CRUD operations in addition to the other CRM-related operations. The nodes that are being used to create a new account are highlighted below. The schema provided by CRM is flexible; it exposes a key-value pair; the key maps to the CRM entity attribute (i.e. name, address1, city, or phone). LogicalName maps to the CRM entity name (i.e. account).
5
Step 4 – Create account schema.
6
Step 5 – Map account schema to the expected CRM schema format.
7
8
Step 6 – Create orchestration in BizTalk. The orchestration is receiving the message viarcvAccountPort; it then uses Construct Message shape to map the message received to the expected Organization Service schema and sends it to CRM. The response message is captured and written to the file system.
9
Step 7 – Deploy BizTalk artifacts to BizTalk.
10

Step 8 – Configure OrganizationService send port.

Import the binding configuration (OrganizationService_Custom.BindingInfo) generated in Step-2. Rename the port from auto generatedWcfSendPort_OrganizationService_CustomBinding_IOrganizationService_Custom toOrganizationService.
CRM Online is using Windows Live Id authentication. In order to configure the BizTalk send port to authenticate with CRM Online instance, a custom WCF behavior has to be built and registered in the Global Assembly Cache (GAC) and the configuration file (machine.config or in BizTalk WCF-Custom send handler).
Mikael HÃ¥kansson’s blog post provides a detailed explanation with the sample code for creating the custom WCF behavior.  I leveraged it for this demo. See below the detailed steps necessary to configure the OrganizationService send port.
OrganizationService send port.
11
OrganizationService Send Port – General tab view.
Note that no changes have been made to the custom binding generated in Step 2.
12
OrganizationService Send Port – Binding tab view.
Select customBinding as the Binding Type.
13
OganizationService Send Port – Behavior tab view
I am using liveIdAuthentication custom behavior which requires the following three properties:
14
Step 9 – Start BizTalk application.
Drop the sample file that contains account-related information in the predefined incoming folder.
15
Sample file:
16
Verify in CRM Online that the account has been added.
17
Verify the response is received in the expected file system folder.
18
The response contains the account id which was automatically generated when the new account entity was created in CRM.
Response Message:
19
The scenario that was presented above used the WCF SOAP Organization Service to integrate with the CRM Online application. Another option typically used for interacting with CRM Online is for BizTalk to leverage a proxy service which in turn uses CRM SDK API to authenticate and communicate with CRM; crmsvcutil tool is part of CRM SDK and can be leveraged to create early bound entity CRM classes that can be used in the proxy service. The proxy service approach is recommended for more complex integration scenarios.

Useful Resources:

No comments:

Post a Comment

How to Deploy your API as a web app or API app

  Before you can call your custom API from a logic app workflow, deploy your API as a web app or API app to Azure App Service. To make your ...