Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Choose your Development Style for Managed Code for Microsoft Dynamics CRM

[Applies to: Microsoft Dynamics CRM 2011]

The Microsoft Dynamics CRM SDK for Microsoft Dynamics CRM 2011 offers a variety of methods and technologies that you can use when you write code to access the Microsoft Dynamics CRM web services or to extend the application. This guide highlights some tools and methods that you can use to accomplish different coding tasks, and offers some guidance on when to use them.

In This Topic

Authenticate using Code

The following table lists the choices you have for writing code that authenticates the caller with an installation of Microsoft Dynamics CRM for on-premises, Internet-facing deployment (IFD), or online deployments.

 

Classes Description and usage More information

Helper code

The classes in the sample code demonstrate how to connect to the web services and authenticate the user. You can use the helper code as a basis of your own custom authentication code.

This code is easy to use and supports all Microsoft Dynamics CRM deployment types. It also supports storing users’ passwords in the Windows Credential Manager for later reuse.

Full source code is provided so you can copy and customize it for your needs. This is a recommended practice to isolate your programs from changes to this helper code in future releases.

Sample: Quick Start for Microsoft Dynamics CRM

Use the Sample and Helper Code

Helper Code: ServerConnection Class

This code can be found in the SampleCode\CS\HelperCode\CrmServiceHelpers.cs and SampleCode\VB\HelperCode\CrmServiceHelpers.vb files in the SDK download.

Developer Extensions

These assemblies are provided to simplify and accelerate the development of applications that interact with Microsoft Dynamics CRM 2011. The extensions extend the functionality of the core Microsoft Dynamics CRM SDK specifically around the use of the OrganizationServiceContext class.

For an easy method that does the hard work for you in a few lines of code, use the CrmConnection class.

This code is easy to use and supports all Microsoft Dynamics CRM deployment types.

Developer Extensions for Microsoft Dynamics CRM

Simplified Connection to Microsoft Dynamics CRM

Xrm client

For advanced developers who need to customize the Windows Communication Foundation (WCF) service channel management and the authentication process, use the IServiceManagment and OrganizationServiceProxy classes in the Microsoft.Xrm.Sdk.Client namespace.

Using these classes directly can provide better connection and authentication performance, and more flexibility. However, they require more advanced knowledge of the WCF service channel and server authentication. In addition, you must write more code to handle all Microsoft Dynamics CRM deployment types.

Active Directory and Claims-Based Authentication

Sample: Authenticate Users with Microsoft Dynamics CRM Web Services

Improve Service Channel Allocation Performance

Create and Deploy Plug-ins or Custom Workflow Activities

The following table lists the choices you have for writing and deploying plug-ins and custom workflow activities.

 

Tool Description and usage More information

Developer Toolkit

The Plugins project provided in the Developer Toolkit for Microsoft Dynamics CRM 2011 and Microsoft Dynamics CRM Online contains a base class named Plugin that implements the IPlugin interface. All plug-in classes generated through the Create Plug-in option of the CRM Explorer will derive from this class.

The workflow project provided in the Developer Toolkit provides support for implementing custom workflow activities for use with your on-premises Microsoft Dynamics CRM instance. Workflow activities that are added to the project that are based on the CRM workflow activity template accelerate the starting point for development.

Using these templates simplifies some of the common coding required, such as obtaining the execution context and tracing services from the service provider and instantiating the organization service proxy.

Use this method when you want to write custom plug-ins and custom workflow activities together with custom entities and attributes, web resources, ribbon controls and other extensions by using Microsoft Visual Studio. This method is useful when you want to write plug-ins or custom activities without having to learn about plug-in and custom activity classes.

Create and Deploy Plug-ins Using the Developer Toolkit

Create and Deploy Workflow Libraries Using the Developer Toolkit

Developer Toolkit for Microsoft Dynamics CRM

Plug-in and Custom Workflow Activity classes

Plug-in Registration Tool

The plug-in and custom workflow activity classes allow you to create event handlers to perform custom business logic that you can integrate with Microsoft Dynamics CRM 2011 to modify or augment the standard behavior of the platform.

By using these classes directly, your code will not contain any helper code provided in the Developer Toolkit.

If you write plug-ins and custom workflow activities from scratch, you must use the Plug-in Registration Tool to register them. This tool provides a graphical user interface and supports registering plug-ins and custom workflow activities with Microsoft Dynamics CRM 2011.

Use this method if you:

Understand how to use the plug-in and custom activity classes.

Don't want extra library code auto-generated and placed in your code files.

Don't mind using an external tool and the web application to register and package custom code assemblies.

Plug-in Development for Microsoft Dynamics CRM

Custom Workflow Activities (Workflow Assemblies) for Microsoft Dynamics CRM

Register and Deploy Plug-Ins

Walkthrough: Register a Plug-in Using the Plug-in Registration Tool

Create and Deploy XAML Workflows

The following table lists the choices you have for writing and deploying XAML workflows.

 

Tool Description and usage More information

Developer Toolkit

The XAML workflow library project in the Developer Toolkit provides support for implementing custom XAML workflows for use with on-premises deployments of Microsoft Dynamics CRM 2011. XAML workflows that are added to the project that are based on the CRM XAML workflow template accelerate the starting point for development.

Use this method when you want to write custom XAML workflows together with custom entities and attributes, web resources, ribbon controls and other extensions by using Microsoft Visual Studio.

Create and Deploy XAML Workflows Using the Developer Toolkit

Developer Toolkit for Microsoft Dynamics CRM

Microsoft Visual Studio Workflow Designer

Microsoft Dynamics CRM (on-premises) supports the ability to create custom XAML workflows. Using the Microsoft Visual Studio Workflow Designer, you can create custom XAML workflows, also called declarative workflows, by dragging workflow activities from the toolbox onto the design surface, creating variables, and setting properties of these activities to implement the workflow’s functionality. You can use built-in Windows Workflow Foundation activities or the process activities that are specific to Microsoft Dynamics CRM.

Use this method when you just want to write custom XAML workflows.

Custom XAML Workflows for Microsoft Dynamics CRM 2011

Write Workflows to Automate Business Processes

Entity Programming (Early Bound vs. Late Bound vs. Developer Extensions)

The following table lists the choices you have for writing code that uses entities in Microsoft Dynamics CRM.

 

Class Description and usage More information

Early Bound

<optional namespace>.Account, <optional namespace>.Contact, and so on

The code generation tool (CrmSvcUtil) creates early-bound entity classes, derived from the Entity class, that you can use to access business data in Microsoft Dynamics CRM. These classes include one class for each entity in your installation, including custom entities.

Use this method when you want to have the compiler check type references at compile time. Also, attributes and relationships are included in the generated class, so they have IntelliSense support for entity, attribute, and relationship names. Using strong types is generally the preferred method and is used in the majority of samples in this SDK documentation.

There are some downsides to this approach:

Classes must be regenerated each time entities are customized to take advantage of schema changes.

Serialization costs increase as the entities are converted to late bound types during transmission over the network.

Use the Early Bound Entity Classes in Code

Create Early Bound Entity Classes with the Code Generation Tool (CrmSvcUtil.exe)

Late Bound

Microsoft.Xrm. Entity

The Entity class contains the logical name of an entity and a property-bag array of the entity’s attributes. This lets you use late binding so that you can work with types such as custom entities and custom attributes that were not present when your application was compiled.

Another benefit of this is that less serialization occurs as entity data is transmitted over a network, which means higher performance.

There are some downsides to this approach:

Types must be explicitly specified to prevent implicit casts.

It is harder to isolate the impact of changes to the schema because the names for resources, such as entities and attributes, are hardcoded.

Spelling mistakes while coding are easier to make because the attribute names are hardcoded strings.

Use the Late Bound Entity Class in Code

Developer Extensions

Microsoft.Xrm.Client. CrmEntity

The CrmEntity class derives from the Entity class. In addition to providing all the same functionality of the Entity class, CrmEntity adds new get and set extension methods to simplify common coding tasks, and two new property change events.

Developer Extensions for Microsoft Dynamics CRM

Early Bound using Code Generation Tool Extensions

<optional namespace>.Account, <optional namespace>.Account, and so on

By using the Developer Extensions version of the CrmSvcUtil tool, you can generate early-bound types that are derived from the CrmEntity class. Use this when you want to take advantage of other features available in the Developer Extensions.

Generate Code with the Code Generation Tool Extensions

Attach Entities to the Context

Developer Extensions for Microsoft Dynamics CRM

Query (Fetch vs. QueryExpressions vs. LINQ vs. Developer Extensions)

The following table lists the choices you have for creating queries you can use to retrieve records from the Microsoft Dynamics CRM database.

 

Query style Description and usage More information

FetchXML

This is a custom XML-based query language that supports all the features of QueryExpression plus aggregates and grouping. Fetch queries can return records for multiple entities. In addition, queries can be serialized and saved in the database. This is used to save a query as a user-owned saved view in the UserQuery entity and as an organization-owned saved view in the SavedQuery entity.

Use this query language when you need support for aggregates and grouping or you need to save the query.

Build Queries with FetchXML

QueryExpression

A query expression is used to search for records for a single entity type. Queries are built as an object model. This class supports all the features in FetchXML except for aggregates and grouping. It also supports both early and late bound entity programming styles.

Build Queries with QueryExpression

LINQ

Queries are built using standard language, but internally LINQ uses QueryExpression, so it is limited to the features of QueryExpression. LINQ supports both early and late bound entity programming styles.

Build Queries with LINQ (.NET Language-Integrated Query)

See Also

Microsoft Dynamics CRM 2011
Send comments about this topic to Microsoft.
© 2013 Microsoft Corporation. All rights reserved.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.