Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 79901

Why does a long running task using OrganizationServiceProxy throw EndpointNotFoundException

$
0
0

I have an application that connects to a D365 (online) instance to replicate some data. In production we're having problems because the datasets are so much larger the replication fails part way with an EndpointNotFoundException.

I've included the code I'm using to establish the connection below.  As you can see from the following snippet from the logs that the authentication token renewal is working perfectly, but sometime after it's renewed, but before the next token renewal is due the EndpointNotFoundException is thrown.

Any suggestions?

I did look at using CrmServiceClient instead of OrganizationServiceProxy however I was unable to work through the dependency hell that came with that because of conflicts with other packages I'm using.

Logs:

...
Renewing CRM authentication token
CRM authentication token renewed, valid to 3/10/2019 7:45:22 AM
...
EndpointNotFoundException dedected in batch 1,124, attempting to re-autenticate
There was no endpoint listening at xxxxx.api.crm6.dynamics.com/.../Organization.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.

private const int TIMEOUT_HOURS = 0;
private const int TIMEOUT_MINUTES = 30;
private const int TIMEOUT_SECONDS = 30;

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

ClientCredentials credentials = new ClientCredentials();
credentials.UserName.UserName = username;
credentials.UserName.Password = password;

IServiceManagement<IOrganizationService> orgServiceManagement = ServiceConfigurationFactory.CreateManagement<IOrganizationService>(new Uri(serviceUrl));

OrganizationProxy = new ManagedTokenOrganizationServiceProxy(orgServiceManagement, credentials)
{
	Timeout = new TimeSpan(TIMEOUT_HOURS, TIMEOUT_MINUTES, TIMEOUT_SECONDS),
	Logger = _log
};


public class ManagedTokenOrganizationServiceProxy : OrganizationServiceProxy
{
	public ManagedTokenOrganizationServiceProxy(IServiceManagement<IOrganizationService> serviceManagement, ClientCredentials userCredentials)
		: base(serviceManagement, userCredentials)
	{
		Authenticate();
	}

	public ITraceWriter Logger { get; internal set; }

	protected override void ValidateAuthentication()
	{
		EnsureAuthentication();
		base.ValidateAuthentication();
	}

	private void EnsureAuthentication()
	{
		if (this.SecurityTokenResponse != null && DateTime.UtcNow.AddMinutes(10) > this.SecurityTokenResponse.Response.Lifetime.Expires)
		{
			if (Logger != null) Logger.Info($"Renewing CRM authentication token");

			Authenticate();

			if (Logger != null) Logger.Info($"CRM authentication token renewed, valid to {this.SecurityTokenResponse.Token.ValidTo.ToLocalTime()}");
		}
	}
}


Viewing all articles
Browse latest Browse all 79901

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>