Programmatically re-login to Epicor when session is expired

Anyone has tried to programmatically re-login to Epicor? We have an issue even tho our session timeout is set to entire day, we still randomly experience session getting expired. We have a stand alone application that uses Epicor BOs and we have a session object that logs the application into Epicor and then we use various BOs to perform some tasks.

Here is a code I use but it crashes with the error below:

image

And here is the error:

System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary2.Insert(TKey key, TValue value, Boolean add) at System.Collections.ObjectModel.KeyedCollection2.AddKey(TKey key, TItem item)
at System.Collections.ObjectModel.KeyedCollection2.InsertItem(Int32 index, TItem item) at System.Collections.ObjectModel.Collection1.Add(T item)
at Epicor.ServiceModel.Channels.ImplBase.ConfigureContextHeader()
at Epicor.ServiceModel.Channels.ImplBase.SetHeaders()
at Epicor.ServiceModel.Channels.ImplBase.HandleContractBeforeCall()
at Epicor.ServiceModel.Channels.ImplBase.CallWithCommunicationFailureRetry(String methodName, ProxyValuesIn valuesIn, ProxyValuesOut valuesOut, RestRpcValueSerializer serializer)
at Epicor.ServiceModel.Channels.ImplBase.CallWithMultistepBpmHandling(String methodName, ProxyValuesIn valuesIn, ProxyValuesOut valuesOut, Boolean useSparseCopy)
at Epicor.ServiceModel.Channels.ImplBase.Call(String methodName, ProxyValuesIn valuesIn, ProxyValuesOut valuesOut, Boolean useSparseCopy)
at Ice.Proxy.Lib.SessionModImpl.Logout()
at Ice.Core.Session.Dispose(Boolean disposing)
at Ice.Core.Session.Dispose()

I’m no expert, but if you are “re logging in” and the guid already exists it’s going to throw that error if the session with that guid already exists. Wouldn’t the new guid be all 000’s. As I said no expert, but that error, seems to be saying it’s doing what’s on the box.

2 Likes

Is there any other way I can login without using GUID?

This sounds promising… But as I said no expert in this aspect of things. I think I have done a session impersonation once in code

or this