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

Notifications

Announcements

No record found.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 83 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

#3
#ManoVerse Profile Picture

#ManoVerse 40

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans