Introduction
This article demonstrates how to integrate Microsoft Dynamics CRM 4.0 using BizTalk Server 2009/2010 to other business applications. There have been several questions on how to talk to Microsoft Dynamics CRM using BizTalk Server 2009/2010 adapters. This article shall attempt to shed some light on it.
Download and Install the Microsoft BizTalk Server Adapter for Microsoft Dynamics CRM 4.0
With this adapter, you can integrate Microsoft Dynamics CRM 4.0 with any other business application using the Microsoft BizTalk Server 2006/2009.
Verify Adapter Installation
Open BizTalk Server Administration console and look for the following:
How to Generate the Required Schemas, to Map and Create Entities in Microsoft CRM?
Once you have installed the adapter correctly, open a new project in Visual Studio.
These steps will generate the required schemas for mapping.
Step 1: Select right-click on Project -> Add -> Add Generated Items -> Select Add Adapter Metadata.
Step 2: Choose Microsoft Dynamics CRM 4.0, click Next and specify CRM connectivity details.
Step 3: Choose the entities and operations.
The project will look like the following after the schema generation:
NOTE: If you have selected more than one entity, the CRM prefixes the schema name with the entity name (for instance Account_Query.xsd). Note that these are common schemas and are identical for every entity. These common schemas can be removed safely and this will reduce the size of schema DLL.
Steps to Invoke CRM Adapter using a Dynamic Send Port
Step 1: Locate the CRM property schema
Locate the property schema in the Dynamics Adapter CRM installation folder (typically located at C:\Program Files\CRMDynamicsBizTalkAdapter4.0\Schemas).
Step 2: Assign the Values for the Property Schema
Set the various properties in the property schema:
CRMAdapterRequestMsg(PropertySchema.ServerUrl) = CRM_URL;
CRMAdapterRequestMsg(PropertySchema.UserName) = CRM_UserName;
CRMAdapterRequestMsg(PropertySchema.Password) = CRM_Password;
CRMAdapterRequestMsg(PropertySchema.CrmOrganization) = CRM_Organization;
CRMAdapterRequestMsg(PropertySchema.AuthType) = CRM_AuthType;
CRMDynamicSendPort(Microsoft.XLANGs.BaseTypes.Address) = CRM_URL;
CRMDynamicSendPort(Microsoft.XLANGs.BaseTypes.TransportType) =
CRM_TransportType;
Step 3: Mapping to Various CRM Operation Schemas
It's required to generate schemas for every entity which needs to be created or updated in the CRM. In this example, I have demonstrated this only for the fetch request. The screen shots illustrate the mapping required to transport to a fetch request.
The crm_action
attribute can take the following values:
create
update (default)
fetch
delete
public string GetFetchQuery(string fetchQueryRequest)
{
return fetchQueryRequest;
}
Downloadable Source Code
This source code contains two orchestrations. One orchestration invokes the CRM adapter and another one calls it using a call orchestration shape. I have coded it to be as generic as possible.
Note the Following Points
Send and Receive Port Settings
HOW to Enable Debugging in Microsoft Dynamics CRM 4.0 BizTalk Adapter and Receive Friendly Error Messages?
The CRM Adapter typically logs error messages in Application Event log. Most of the error messages are generic and do not give enough descriptive meaning. The following are the steps required to log errors in a log file with descriptive error messages.
Step 1: Open Registry Editor
Search for the following key '6B8335E2-9664-4ad8-A2F6-ADBFD60FF703'.
Step 2: Set the following keys as shown in the screen shot:
Step 3: Re-start the BizTalk send handler associated with the CRM adapter
You are all set for a happy integration.
Typical Error Messages in CRM Adapter Logs
Error Message |
Exception :: 0x80040203 :: serializedForm :: at
System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse
(SoapClientMessage message, WebResponse response, Stream responseStream,
Boolean asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke
(String methodName, Object[] parameters)
at Microsoft.Crm.BizTalkAdapter.CrmService2007.CrmService.Execute
(Request Request)
at Microsoft.Crm.BizTalkAdapter.Runtime.SendToCrm.UpdateDynamicEntity
(EntityAttributesValidationResult attributeValidationResult,
String entityName)
|
Solution | The error code 0x80040203 means that a primary key of the entity is not set or there is a mandatory element whose value is missing in the entity. |
Error Message |
Attribute :: xxx_currencyid, Attribute Type :: Lookup,
Attribute Value :: USD, Error :: There is an error in the XML document.
|
Solution | Firstly note that the attribute type is a Lookup. Every lookup type has the following four attributes:
The CRM documentation tells us that the attributes IsNull , name and dsc are optional. You can set IsNull to true in case you want to update the value of the element to NULL explicitly.
Workaround: Set the value to the attribute name , instead of the element and voila, this error might go away. Note that eventually you might have to set the right GUID value to the tag.
<xxx_currencyid name="USD" />
|
Quick References
I suggest having a look at the following post by Brajendra Singh as a starter and some notes on CRM adapter debugging.