Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

How to fix SecurityNegotiationException while running Parallel.Foreach

Posted on by Microsoft Employee

Hi,

I am getting the following exception (after my code runs for some time and updates some records) when I run ExecuteMultipleRequest in parallel using Parallel.ForEach   : 

Exception thrown: 'System.ServiceModel.Security.SecurityNegotiationException' in Microsoft.Xrm.Sdk.dll

The application terminated with an error.

Secure channel cannot be opened because security negotiation with the remote endpoint has failed. This may be due to absent or incorrectly specified EndpointIdentity in the EndpointAddress used to create the channel. Please verify the EndpointIdentity specified or implied by the EndpointAddress correctly identifies the remote endpoint. 
The request for security token has invalid or malformed elements.

My code runs properly until I set MaxDegreeOfParallelism greater than 3.


I have used  "service.Timeout = new Timespan(0,30,0);"

and I have also included the following binding in app.config

<system.serviceModel>
  <bindings>
    <wsHttpBinding>
       <binding openTimeout="00:50:00"
                      closeTimeout="00:50:00"
                      sendTimeout="00:50:00"
                      receiveTimeout="00:50:00">
       </binding>
   </wsHttpBinding>
 </bindings>

</system.serviceModel>

 

How can I fix this error ??

Also the authentication type for my Crm instance is AD so the SecurityTokenResponse is null for the OrganisationServiceProxy (in case this information is related to the exception).

*This post is locked for comments

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: How to fix SecurityNegotiationException while running Parallel.Foreach

    Hi Ben,

    The recommended MaxDegreeOfParallelism is said to be 2 for ExecuteMultipleRequest. For na on premise system , throttling is not enabled by defaut but can be set by updating the deployment properties.

    "Throttling of concurrent calls – for Microsoft Dynamics 365 (online) there is a limit of 2 concurrent ExecuteMultipleRequest executions per organization. If that limit is exceeded, a “Server Busy” fault is thrown before the first request is ever executed. For an on-premises deployment, throttling is not enabled by default. The deployment setting for this limit is ExecuteAsyncPerOrgMaxConnectionsPerServer."

    Refer this: https://msdn.microsoft.com/en-au/library/jj863631.aspx#limitations 

    Hope this helps.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans