Click here to Skip to main content
Click here to Skip to main content

Tagged as

Go to top

How to Integrate Microsoft Dynamics CRM 4.0 using BizTalk Server 2009/2010 to Other Business Applications

, 17 Mar 2011
Rate this:
Please Sign up or sign in to vote.
This article demonstrates how to integrate Microsoft Dynamics CRM 4.0 using BizTalk Server 2009/2010 to other business applications.

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:

CRM_Adapter.JPG

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:

CRM_Schemas.JPG

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:

// NOTE: These are dynamic port assignments. 
// These can changed at runtime without any impact! 
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;

// NOTE: Specify the CRM full URL endpoint. 
CRMDynamicSendPort(Microsoft.XLANGs.BaseTypes.Address) = CRM_URL;

// NOTE: match this with the adapter name in BizTalk Server 
// Administration Console (Microsoft Dynamics CRM 4.0)
CRMDynamicSendPort(Microsoft.XLANGs.BaseTypes.TransportType) = 
		CRM_TransportType; // "Microsoft Dynamics CRM 4.0"

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

FetchCRMRequest_Map.JPG

 

// Custom Functoid code to send RAW XML
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

  • The CRM adapter uses the following namespace for sending a response back to the orchestration. The xxx value must be replaced by the specific CRM value that you connect with.
    http://schemas.microsoft.com/crm/2007/BizTalkAdapter/xxx/Response 
  • There are two forms of response from CRM, the error response and the correct response. The error response is shown in the attached screen shot. The correct response is under the /Body/Message tag and the ReturnCode value will be 1. The orchestration code extracts the response from the Message tag and transmits it to the logical sent port.

    CRM_Adapter_Response.jpg

  • Notice the send port and receive port settings. This is not required in production, but it is required to run this code.

Send and Receive Port Settings

  • CRM_Adapter_SendPort_Settings.JPG CRM_Adapter_RcvPort_Settings.JPG

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:

RegistryKeys.JPG

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:

LookupListValues.JPG

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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Naveen Karamchetti
Architect AT&T Wi-Fi Services
United States United States
Naveen has done his Masters (M.S.) in Computer science, has started his career programming the mainframes and now has more than a decade of programming, development and design experience. Naveen has a sharp eye and keen observation skills. Naveen has worked for several companies and strived hard to build large scale business applications and bringing better solutions to the table.
Quite recently Naveen has built a fairly complex integration platform for a large bank. His hobbies include training, mentoring and research. Naveen spends his free time visiting National Parks nationwide.
 
Naveen has developed the BizTalk Control Center (BCC)
http://biztalkcontrolcenter.codeplex.com

Comments and Discussions

 
GeneralThanks for your article. Pinmemberxz_king14-Dec-12 17:40 
QuestionDynamics CRM 4.0 integration PinmemberWilsonLast10-May-12 3:08 
QuestionHow can I integrate with CRM and Project Server? PinmemberMember 446046328-Feb-11 7:36 
QuestionExample? PinmemberVertyg07-Feb-11 21:15 
AnswerRe: Example? PinmemberNaveen Karamchetti8-Feb-11 12:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140921.1 | Last Updated 17 Mar 2011
Article Copyright 2011 by Naveen Karamchetti
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid