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 :
Microsoft Dynamics CRM (Archived)

How to fix SecurityNegotiationException while running Parallel.Foreach

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    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

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans