简体   繁体   中英

How can i solve this error “System.ServiceModel.FaultException”

Everytime I stop the program and rerun again the error message pop

PX.Data.PXException: API Login Limit at PX.Api.ContractBased.Soap.WebApiSoapController.Post(ISoapSystemContract systemContract, XmlReader requestReader, String serviceNamespace, String internalNamespace, MethodInfo method, Func 1 serviceFactory, IEdmModel edmModel) at PX.Api.ContractBased.Soap.WebApiSoapController.<Login>d__6.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Threading.Tasks.TaskHelpersExtensions.<CastToObject>d__3 1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Controllers.ApiControllerActionInvoker.d__0.MoveNext() --- End of stack trace fr om previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Controllers.ActionFilterResult.d__2.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Controllers.ExceptionFilterResult.d__0.MoveNext()

this is my code on log in

...
using (DefaultSoapClient soapClient = new DefaultSoapClient())
{
       //Log in to Acumatica ERP        
       soapClient.Login
       (
            Properties.Settings.Default.UserName,
            Properties.Settings.Default.Password,
            Properties.Settings.Default.CompanyName,
            Properties.Settings.Default.Branch,
            null
       );
 ...
      try
      {
           ...
           soapClient.Logout();
      }
      catch (Exception e)
      {
           ...
           soapClient.Logout();
      }
      finally
      {
           ...
      }

what's wrong with my code and how do I fix it?

Unlicensed demo versions have a limited amount of API connection session available.

You have to make sure Logout is always called after Login otherwise you'll run out of available connection sessions. For unlicensed version you should aim for a maximum of 1 connection at any time and make sure the application can't be stopped without executing the API connection session logout.

Here's the stategy I would use to ensure that:

  • Use only single threaded code to interact with the API because you want to avoid multiple concurrent connections when using unlicensed version.

  • Wrap all code interacting with the API in exception block that will always call logout. It doesn't hurt to be paranoid here, you can event put the login code in the try block because if login fails there's no harm in trying to logout.

  • Try to make your session short and to the point, don't login pre-emptively or keep the connection opened for longer than required. Having sessions hanging around for too long increases the chances of losing the connection before you can issue the logout command or simply forgetting to logout.

  • Register an application wide OnClose event handler to Logout of the session when the user soft closes the application. If the user hard closes the application (ex: by killing it with task manager) you can't execute logout so you'll have to wait for the session to expire or restart IIS to avoid API connection limit exceeded errors.

  • Log each connection login/logout attempts to disk (whether successful or not) to make sure it always calls logout for each login. When login is executed create a unique id for that connection and log it, when logout is executed log it with the same unique id. If you get the API limit error again you'll have log data to confirm whether or not you have successfully logout of all opened sessions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM