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, Func1 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__31.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 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.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.
Related
I'm having an Access Denied message while executing this code:
var report = await _service.RenderAsync(new RenderRequest
{
Template = new Template
{
Recipe = Recipe.PhantomPdf,
Engine = Engine.None,
Content = html,
Phantom = new Phantom()
{
Header = header,
Footer = footer,
HeaderHeight = GetElementHeightOrDefault(header),
FooterHeight = GetElementHeightOrDefault(footer)
}
}
});
Actually it fails while executing the _service.RenderAsync method, a service that implements from IRenderService.
This is the error message:
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
at jsreport.Local.Internal.BinaryProcess.<InnerExecute>d__18.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.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at jsreport.Local.Internal.BinaryProcess.<ExecuteExe>d__17.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.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at jsreport.Local.Internal.LocalUtilityReportingService.<RenderAsync>d__10.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.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
I found this thread from jsreport in which there's people with the same problem as me: formu.jsreport.net/topic/428
So I followed this steps:
As I have a Web application and an IIS Api service in IIS, I added both IUSR and IIS_IUSRS to the applicaitons and gave them the highest permissions
Ensured that my solution was executed under admin privileges
Disabled all antivirus and Windows Security
But none of these worked. I'm still fancing the same problem here.
Can anybody help me?
Probably it's something related to the impersonation, so if the code not executed under a specific impersonation context and all of the code runs through the IIS Impersonation so we may need to make some trails related to the AppPool:
Try to change the impersonation in your AppPool to admin user:
IIS > Application Pools > Advanced Settings > Identity (and change it
to the Admin account).
Give the directory which contains the rendering stuff an everyone
permission.
Also, as per your comment, The local system has the highest privilege while network service or ApplicationPoolIdentity has the least-privilege to execute the application so that's why local system can solve most of the impersonation issues .
HttpClient throw a random exception ( maybe 2-3 times out of 10 attempts ) with Azure Container Instance
Exception Info: System.Net.WebException at
System.Net.HttpWebRequest.EndGetResponse(System.IAsyncResult) at
System.Net.Http.HttpClientHandler.GetResponseCallback(System.IAsyncResult)
Exception Info: System.Net.Http.HttpRequestException at
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)
at
System.Net.Http.HttpClient+\u003cFinishSendAsync\u003ed__58.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSucem.Net.Http.HttpClient+\u003cFinishSendAsync\u003ed__58.MoveNext()
at
SystetHelpers.MSIResourcesAccessInfoHelper+\u003cGetResourcesAccessInfo\u003ed__0.MoveNext()\n.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\n
at System.Runtime.m[[System.__Canon, mscorlib, Version=4.0.0.0,
Culture=neutral,
PublicKeyToken=b77a5c56193ompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.ThreC.Main(System.String[])
On the code side, I am simply firing
await httpClient.GetAsync($"http://xyz.eastus.cloudapp.azure.com/api/controller/{id}");
response.EnsureSuccessStatusCode();
return await response.Content.ReadAsAsync<ResourceAccessInfo>();
The behavior is very random it happens only 2-3 time out of 10 attempts
I have also applied re-try when the first attempt then try the second time but still it fails
Same works fine with VM containers always.
Updated:
Additional Exception Info:
System.Net.Http.HttpRequestException: An error occurred while sending the request. ---\u003e System.Net.WebException: The remote name could not be resolved: \u0027cloudbridge1.eastus.cloudapp.azure.com\u0027\r\n at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)\r\n at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar)\r\n --- End of inner exception stack trace ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Net.Http.HttpClient.\u003cFinishSendAsync\u003ed__58.MoveNext()\r\n--- End ofstack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at UcClearly.MSIAPIHelpers.MSIResourcesAccessInfoHelper.\u003cGetResourcesAccessInfo\u003ed__0.MoveNext()
Which suggest remote server DNS not resolved, I tried with public IP of the server also but same random behavior, I am not sure why Azure Container instance behave this random way
This behaviour is expected.
Windows containers slow network readiness
On initial creation, Windows containers may have no inbound or outbound connectivity for up to 30 seconds (or longer, in rare cases). If your container application needs an Internet connection, add delay and retry logic to allow 30 seconds to establish Internet connectivity. After initial setup, container networking should resume appropriately.
https://learn.microsoft.com/en-us/azure/container-instances/container-instances-troubleshooting#windows-containers-slow-network-readiness
I am working on an MVC web application that uses Google Natural Language Processing API to parse different input from users.
I have successfully consumed and implemented the API operations and everything works fine as long as I run the application on my local machine. But as soon as I publish a version and upload it on a server I receive the following error on calling the API methods (e.g. AnalyzeSentiment):
Status(StatusCode=Unauthenticated, Detail="Getting metadata from plugin failed with error: Exception occured in metadata credentials plugin.")
With the help of the answers from post: Google Datastore authentication issue - C# I was able to further get details on the error (using gRCP):
An error occurred while sending the request.
Stacktrace: at Google.Apis.Http.ConfigurableMessageHandler.<SendAsync>d__58.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 Google.Apis.Auth.OAuth2.Requests.TokenRequestExtenstions.<ExecuteAsync>d__0.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 Google.Apis.Auth.OAuth2.ServiceAccountCredential.<RequestAccessTokenAsync>d__19.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 Google.Apis.Auth.OAuth2.ServiceCredential.<GetAccessTokenForRequestAsync>d__23.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 Google.Apis.Auth.OAuth2.ServiceAccountCredential.<GetAccessTokenForRequestAsync>d__20.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 Grpc.Auth.GoogleAuthInterceptors.<>c__DisplayClass2_0.<<FromCredential>b__0>d.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 Grpc.Core.Internal.NativeMetadataCredentialsPlugin.<GetMetadataAsync>d__11.MoveNext()
This seemed like an authentication issue so I double checked the jsonKey file which is fine. Please note, I have used code to set the credentials in Environment variables:
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", jsonPath);
and verified it using:
Environment.GetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS")
The call is made as follows:
private AnalyzeSentimentResponse AnalyzeSentiment(string statement)
{
GrpcEnvironment.SetLogger(new MyLogger());
var client = LanguageServiceClient.Create();
var response = client.AnalyzeSentiment(new Document()
{
Content = statement,
Type = Document.Types.Type.PlainText
});
return response;
}
Cannot figure out why it works fine when I run it on my local machine and fails when it is deployed on the server. There is also no restrictions of any kind on the said server.
The result for:
GoogleCredential.GetApplicationDefaultAsync().Result.UnderlyingCredential.GetType()
is:
Google.Apis.Auth.OAuth2.ServiceAccountCredential
Note: The server is our own (Windows Server 2012R2)
With the suggestion given by #JonSkeet, I copied the code into a console application and executed the call. Unfortunately, the issue persisted. What I did next was to move the console application onto another server, it worked there.
So, it was indeed an issue with the server where there maybe some features missing (the firewall is disabled). Network dept is checking it out whereas I have deployed my web application on another server.
Update: There was an issue on the server where some required framework features were not installed. The issue has been resolved by moving the deployment to another server.
I just made an WebApi (C#, .net 4.5.2) and published it to the web. In order to make sure it working good, I started a to test it.
The REST web-service failed the "stress" test. I sent the service 30+- http requests, each second, and got back this typical error message:
System.OperationCanceledException: The operation was canceled.
at System.Threading.CancellationToken.ThrowOperationCanceledException()
at System.Net.Http.HttpContentExtensions.<ReadAsAsyncCore>d__0`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.ModelBinding.FormatterParameterBinding.<ExecuteBindingAsyncCore>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Controllers.HttpActionBinding.<ExecuteBindingAsyncCore>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>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.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext()
Same error occurred many times in the log.
When I entered the specific machine, I saw that the CPU is on 100% and the RAM is on 80%. Which mean, the machine gives her best to handle the load.
Questions
According to the StackTrace I provided above, I cannot understand
where exactly was the problem in my code?
My code is scale out automatically (hosted in the cloud). But, new machine created only after 5 minutes (depends on the average CPU > 50%). How should I handle sudden mass of HTTP request? Maybe the server should say: "Hey, try agian in 30 seconds" or something like that? What is the right solution?
System.OperationCanceledException: The operation was canceled.
This usually indicates that the client connecting to the service closed the connection before the service could send a response. In terms of api layer this usually means that you have specified a timeout while establishing the http connection, or the library that you are using for making http calls has a default timeout.
You may want to check the iis request logs to see what is going wrong. Since this is happening on a stress test, my guess is your service is running short of threads (Read this for more details) . You may want to consider async model for your request handlers to improve the scalability and utilize threads better. (Read this)
I'm getting this exception when awaiting LoginAsync:
await fb.LoginAsync("user_about_me");
The full stack trace is the following:
{System.InvalidOperationException: Operation is not valid due to the current state of the object.
at Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(Task task)
at Microsoft.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at Microsoft.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at FacebookServiceClient.FbServiceClient.<Login>d__0.MoveNext()}
I'm using Facebook Client 0.5.0.
The strange thing is that this error doesn't always occur, usually when I start a coding session everything is just fine, but then (after a few debug sessions) this exception popups every time.
Any thoughts?
Edit: I have this problem even on the SDK github sample
The problem is not anything to do with the operation itself after browsing the code I found out that the problem is when the browser fails to connect to facebook this exception is thrown.