More About This Website

All information is provided "AS IS" with no warranties, and confers no rights

Powered by Squarespace
« Choosing Smart Defaults for New Entities | Main | Using Early Types across assemblies in plugins »

CRM Client Extension Data Access Strategies

The following are the three primary options for accessing CRM data/services from a client side extension that is implemented as a web resource:

  • REST endpoint that implements the OData protocol
  • SOAP endpoint for web resources
  • Commanding Pattern using either of the prior options

Each of these approaches can be used regardless of HTML (with scripting) or Silverlight client extensions. Keep in mind for standalone client applications there are other considerations not covered.

Synchronous vs. Asynchronous

Requests from the client extension to the CRM server requests can be made synchronous or asynchronously. The best practice is to use asynchronous requests to ensure the best user experience. Synchronous requests by nature can block the UI. Developers like Synchronous requests because it simplifies the programming model. Similar simplification of Async requests using C# async /await support or a similar library for scripting often times minimizes the programming challenges.

REST Endpoint using OData

The REST endpoint implements the OData protocol ( to allow flexible access to CRM data. This supports basic data access (Create, Retrieve, Update,Delete) but does not allow execution of CRM service requests like Start Workflow, or any Meta Data access.

Use When

  • Low volume data access
  • Client side control of transaction is not required. By client side control of transactions this means where you need deterministic control if all changes are made or rolled back.

Avoid Use When

  • Interactions that require large number (typically > 10-25 at a time) requests to server
  • Interactions that require all to work or all to fail – you need a client controlled transaction
  • You need aggregate values – the SOAP endpoint is preferred then because you can run a Fetch Query
  • You need formatted values that are returned from the SOAP service or Option Set labels – or at least understand you need to handle this yourself.

It’s worth noting that while OData provides a flexible query pattern but can be slightly bloated in the size of data it returns. This can be mitigated using $select or by qualifying the data being returned.

SOAP Endpoint

The SOAP endpoint extends to the client the CRM Organization service giving access to both data and service operations. This includes the ability to query and modify CRM metadata.

Use When

  • You need access to CRM Services or Metadata
  • For basic data access OData is not working
  • When you want control of setting Related entities which can simulate a client side transaction. For example you could insert an Account and related Activities in one server interaction. This is only available for related entities to the primary entity being created/updated.

Note: SDK documents Deep Insert for the REST endpoint that can accomplish similar actions but it is not documented if this is within the scope of a transaction

  • Low volume data and service access
  • Client side control of transaction is not required beyond related entities

Avoid Use When

  • Interactions that require large number (typically > 10-25 at a time) requests to server, this is similar to the REST endpoint
  • Interactions that require all to work or all to fail – you need a client controlled transaction
  • For basic data access unless OData is not meeting needs

Commanding Pattern

The commanding pattern allows a client side requests to be communicated to the server and processed by a plug-in. The plug-in can run in a transaction and can perform one or more CRM service operations all of which would be included in the transaction. This pattern is best used when client extensions need to perform many server interactions or need support for client controlled transactions. This pattern also moves the chatty requests from client side with high latency to server side with low latency improving the total time to perform multiple operations. Additionally, if you have existing server code performing business logic, this pattern allows easy reuse.

The mechanics of this approach is a custom entity is created. Let’s call it “ServerCommand”. It contains at a minimum a RequestData attribute and a ResponseData attribute. The client extension using either OData or SOAP creates a ServerCommand entity instance populating the RequestData attribute. Server side a plug-in is created and registered against the Pre-Operation Create on ServerCommand. The plug-in looks at the RequestData does whatever work it needs to do and places the results in ResponseData. That work could be one or more service calls or data operations. Because this is done in the Pre-Operation stage of the event pipeline the response is written to the database during the create operation requiring no extra updates. Back client side, using the ID returned from Create the client extension would perform a read operation to get the ResponseData that was created by the plug-in. Server side you do need to bulk delete the completed ServerCommand records at some point.

Use When

  • You need client controlled transactions
  • You need to perform several operations
  • You need to server side logic
  • You want to shift processing to the server

Avoid Use When

  • You don’t need client controlled transactions
  • You are only making a few calls

Mix and Match

While it would be nice to suggest one single approach for working with CRM data / services, however as client extensions become more complex a single approach is likely not optimal. By using a mixed approach you can take the best of each of the patterns above as needed to provide the best user experience and meet the demands of the client extension.

Using a manager style class or other client side code pattern that hides the details of the implementation for each interaction with the CRM server client side developers can isolate the code and choices and giving flexibility for future changes. This technique is also helpful in larger client extension developed by multiple developers or where many client side extensions need the same interactions with the CRM server.

Wow, you made it to the end Smile  If you made it this far and have opinions drop me an e-mail.

EmailEmail Article to Friend

References (12)

References allow you to track sources for this article, as well as articles that were written in response to this article.
  • Response
    Response: Similar Opinions
    You made various nice points there. I did a search on the topic and found the majority of folks will have the same opinion with your blog.
  • Response
    Response: Added Input
    Hello, i believe that i noticed you visited my website so i got here to “return the desire”.I am trying to find issues to enhance my web site!I assume its good enough to use some of your ideas!!
  • Response
    Response: Helpful Insight
    I was wondering if you ever considered changing the layout of your site? Its very well written; I love what youve got to say. But maybe you could a little more in the way of content so people could connect with it better. Youve got an awful lot of text for ...
  • Response
    Response: Expanded Reading
    I simply wanted to write down a quick word so as to appreciate you for all the stunning information you are giving here. My prolonged internet look up has at the end been compensated with sensible suggestions to go over with my companions. I 'd believe that most of us readers ...
  • Response
    What I have seen in terms of personal computer memory is the fact that there are features such as SDRAM, DDR and the like, that must match the features of the motherboard. If the personal computer's motherboard is very current and there are no os issues, updating the memory literally normally ...
  • Response
    - MrDave's (David Yack) CRM Blog! - CRM Client Extension Data Access Strategies
  • Response
  • Response
    Strategic processes, ideas, goals further ends for businesses furthermore organizations are documented annually in a comprehensive important plan. The strategic plan is a document that provides vision to managers of employees about tasks further management affairs to occur for the organization's success.
  • Response
    - MrDave's (David Yack) CRM Blog! - CRM Client Extension Data Access Strategies
  • Response
    Response: bad credit loan
    - MrDave's (David Yack) CRM Blog! - CRM Client Extension Data Access Strategies
  • Response
    Response: dumpsters
    - MrDave's (David Yack) CRM Blog! - CRM Client Extension Data Access Strategies
  • Response
    - MrDave's (David Yack) CRM Blog! - CRM Client Extension Data Access Strategies

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
All HTML will be escaped. Hyperlinks will be created for URLs automatically.