Looking for PowerObjects? Don’t worry, you’re in the right place! We’ve been part of HCL for several years, and we’ve now taken the final step in our acquisition journey: moving our website to the HCL domain. Nothing else is changing – we are still fanatically focused on Microsoft Business Applications!

PowerObjects Blog 

for Microsoft Business Applications

|

How to properly connect to CRM

Post Author: Joe D365 |

For Microsoft Dynamics CRM, there are various ways to connect to CRM's web services. In many applications, such as a web portal, a long lived and cached connection is desired. A common rookie mistake is to open a connection and assume it is open and alive for ever. If the security token does expire or become invalid, and a check is not done properly, an error such as this will be encountered:

"The HTTP request to 'https://org.crm.domain.net//XRMServices/2011/Organization.svc' was aborted. This may be due to the local channel being closed while the request was still in progress. If this is not desired, then update your code so that it does not close the channel while request operations are still in progress."

The reason for this message is the connection to CRM has terminated such as due to an expired security token or an iisreset and the code assumed the connection was still open.

The issue can be resolved by following the below steps:

  • Create a connection string to the CRM org in the configuration file as shown below.

    Microsoft Dynamics CRM Web Services

  • Use the Connection string in the using statement around the service method being executed (that is each time we execute/call a CRM service method just instantiate the service and surround inside using statement) as shown below.

    We can also call different service methods inside one using statement for a more efficient code.

    CRM Support

This solution may seem simple, but it takes care of caching the security token and will re-connect if it expires. This can then reduce or eliminates http request aborted errors.

Happy CRM'ing!

Joe CRM
By Joe D365
Joe D365 is a Microsoft Dynamics 365 superhero who runs on pure Dynamics adrenaline. As the face of PowerObjects, Joe D365’s mission is to reveal innovative ways to use Dynamics 365 and bring the application to more businesses and organizations around the world.

2 comments on “How to properly connect to CRM”

  1. Could this be used in a scenario where multiple users are concurrently accessing an external web site registration form which will call the OrganisationService.

    Alan

    1. Hi Alan -- yes and we would highly recomend this for any external web site/portal that connects to crm.

PowerObjects Recommends