I encountered a weird problem. The same code runs on my local environment without any errors, but a time out error occurs when running on a test environment. I don’t know if anyone has encountered the same problem.
Just like the picture below, when I click the Batch Sync Product button, a method will be executed,
But there will be a time out error message, which makes me feel very confused
Unfortuantely you gave us no information about your code, but isn't it the same as in your previous thread, Extending RunBaseBatch Class to Create and Run a Batch?
If so, you seem to have a problem with a web service you're calling.
You might collect more information about your problem if you run your code in debugger.
I have no way to debug my code in the test environment, how can I find out where the error is reported?
You can connect your DEV environment to the Test database and try your process again data from Test environment. See Debug a copy of the production database.
Also, didn't yopu say that you can reproduce the error in your DEV environment as well just by ruinning your code in batch?
I have used the test environment database in the local development environment, but the time out error cannot be reproduced
Then debugging the batch may be a good idea. It's likely both caused by the same problem.
Also, what about debugging the service called by your class? Does it get called at all? Is it responsive?
Sorry, I don’t quite understand the meaning of this sentence
The purpose of your code is calling a web service or something (via HttpRequest). All I know about it is what you told us, which is nothing, therefore I can't say anything more about it.
Anyway, you're calling something and you're getting a timeout exception, therefore it seems likely that this something doens't respond. Therefore you should check out what's going on - does it get called at all, or does something fail before even reaching the web service? Or does it get called but it gets stuck or too busy?
I just did a test. When I called this code, it was indeed running, and a timeout error occurred after 102 times of execution.
What does it mean? Does the something time out or not? Remember, you're trying to locate the source of the error.
Maybe you run out of certain resources. There is indeed bug in your code - you're not disposing the response (you're also not disposing the request in case of a failure).
It can be easily done with the 'using' statement. It makes sure that resources are disposed regardless if things succeed or fail. For example:
using (HttpWebResponse response = request.GetResponse())
using (StreamReader streamRead = new StreamReader(response.GetResponseStream()))
Hello, Martin DrábI will now use the code example you gave. There is no problem using it locally. The code has been executed 1000 times in a loop, but when I use the same code in the test environment, the time out error occurs again.I have now found the reason for the time out error.The reason for the error seems to be that the token acquisition failed after the loop was executed 100 times.The error is as follows:
error message “Can read the token but failed validating token with exception 'IDX10205: Issuer validation failed. Issuer: 'https://sts.windows.net/57206206-ec82-4579-9724-0a098ed1b99f/'. Did not match: validationParameters.ValidIssuer: 'null' or validationParameters.ValidIssuers: 'https://wkea-test.sandbox.operations.dynamics.com, 00000015-0000-0000-c000-000000000000, https://wkea-test.sandbox.operations.dynamics.com, https://sts.windows.net/64b7148c-0b9a-41a5-b758-dfd930b73a89/'.'
at System.IdentityModel.Tokens.Validators.ValidateIssuer(String issuer, SecurityToken securityToken, TokenValidationParameters validationParameters)
at System.IdentityModel.Tokens.JwtSecurityTokenHandler.ValidateToken(String securityToken, TokenValidationParameters validationParameters, SecurityToken& validatedToken)
at Microsoft.Dynamics.ApplicationPlatform.SystemSecurity.SignedJwtSecurityTokenHandler.ValidateToken(String securityToken, TokenValidationParameters validationParameters, SecurityToken& validatedToken)
The token validation failed. From confirguration allowed ValidIssuers : 'System.Collections.Generic.List`1[System.String]'
ValidAudiences : 'System.Linq.Enumerable+<ConcatIterator>d__59`1[System.String]'”
he token expired because of the session timeout?
You've never mentioned any token; your code doesn't contain any reference to any token either. Therefore I can't comment on your logic regarding tokens.
By the way, if you missed my previous reply, please read it now and then add proper resource dealllocation to your code. It might solve some of your problems.