web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Unanswered

"The underlying connection was closed: A connection that was expected to be kept alive was closed by the server." issue

(0) ShareShare
ReportReport
Posted on by 35

We are using OrganizationServiceProxy object (created by using the Microsoft.Xrm.Tooling.Connector.CrmServiceClient) to access CRM in our web service functions. From time to time, we would encounter this "The underlying connection was closed: A connection that was expected to be kept alive was closed by the server." WebException. Can anyone give a solution to solve this problem?

Searching on internet, it is suggested that setting the connection KeepAlive to false can solve the problem. However, the OrganizationServiceProxy does not provide a way to change this property. Can somebody help?

I have the same question (0)
  • David Jennaway Profile Picture
    14,065 on at

    There's not a direct KeepAlive property that you can use. The general pattern that I use is to catch the exception and recreate the OrganizationServiceProxy object.

    Alternatively, as the main reason for the connection to be close is that the security token has expired, you can check if the security token is about to expire (via the SecurityTokenResponse property), and if so, reauthenticate using the Authenticate method.

  • Tao Song Profile Picture
    35 on at

    Thanks David for the suggestion.

    We already implemented the auto refreshing token mechanism. So security token expiration may not be the reason.

    Can the OrganizationServiceProxy object be used again after the failure? If we have to create a new proxy object, it will be too much hassle because the object is not passed in process functions by reference, and it is used across several places within one business process function.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 184 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 125

#3
CU11031447-0 Profile Picture

CU11031447-0 100

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans