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 ‘‘ 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!

Avatar for Joe D365

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.