SmartConnector Forum
Schneider Electric support forum about SmartConnector applications for integration of other building management systems (BMS) into EcoStruxure Building Operation.
Link copied. Please paste this link to share this article on your social media post.
Dear Community,
I am developing a processor which makes an API call to download data from a third party system.
I make the call with an HttpClient object
// Creation
httpClient.DefaultRequestHeaders.Accept.Clear();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
// Basic authorization
var byteArray = Encoding.ASCII.GetBytes(UsernameStarRezAPI + ":" + PasswordStarRezAPI);
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
// Download call
Task<HttpResponseMessage> t = httpClient.PostAsync(URLStarRezAPI + "/query", byteContent);
t.Wait(new TimeSpan(0,0,30));
HttpResponseMessage response = t.Result;
The call data (url, authentication, data format) are correct, because if I use it from a client such as ARC and I have no problems.
If I make the call with the processor in debug, the call is made correctly and the requested data is returned.
If I load the processor into the SmartConnector, compiling it in release, the Wait call goes into exception:
2021-10-25 11:46:45.9328,[SEStarRezProcessor] DownloadReservationFromStarRezAPI Si sono verificati uno o più errori.
in System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
in System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
in System.Threading.Tasks.Task.Wait(TimeSpan timeout)
in EsxSEStarRezProcessor.SetupProcessor.<DownloadReservationFromStarRezAPIAsync>d__35.MoveNext(),
Can you help me to understand what can be the cause?
The API is in https, I don't know if there are any limitations on this.
Thanks for your availability and support,
Sabrina
Link copied. Please paste this link to share this article on your social media post.
Dear Colleagues,
we solved, and here's the solution, in case someone has the same problem:
Sniffing the API calls made we saw that the problem was that the StarRez server requires the use of Tls1.2 for https calls, while the Smart Connector makes those calls using Tls1 by default (unless otherwise specified) .
For some reason when we run it in debug the calls are made by default with the correct Tls protocol so the problem was not detected.
We forced the correct version into the call and fixed the problem.
Sabrina
Link copied. Please paste this link to share this article on your social media post.
Hi Sabrina,
I assume you are on the corperate network, i expirenced the same with HTTP(S) requests working in the debug but not in the framework, what you need to do is change the service log on from local system account to this account and use your SESA credentials. Keep in mind to change it when you change your SE login every 6 months. See attachment for the settings
Link copied. Please paste this link to share this article on your social media post.
Hi Erwin,
thank you for your suggestion,
We changed the log on of the service but unfortunately it didn't solve the problem.
Any other ideas?
It can be the basic authentication the problem?
Thanks again
Sabrina
Link copied. Please paste this link to share this article on your social media post.
Hi Sabrina,
The stack trace you get is very generic, I'd try to catch the exception(just wrap your code in a try-catch) and log as much as you can. How long does the processor run before erroring out?
BR
Armend
Link copied. Please paste this link to share this article on your social media post.
Dear Colleagues,
we solved, and here's the solution, in case someone has the same problem:
Sniffing the API calls made we saw that the problem was that the StarRez server requires the use of Tls1.2 for https calls, while the Smart Connector makes those calls using Tls1 by default (unless otherwise specified) .
For some reason when we run it in debug the calls are made by default with the correct Tls protocol so the problem was not detected.
We forced the correct version into the call and fixed the problem.
Sabrina
Link copied. Please paste this link to share this article on your social media post.
Good catch!
Smartconnector is TLS "agnostic" and will let the OS decide what protocol to use.
There's a lot of good info here, including how to "prefer" TLS 1.2 system wide instead of in code.
https://docs.microsoft.com/en-us/dotnet/framework/network-programming/tls
Not sure why it would be different while debugging and in the service in your case though, if you have any hints please let me know 🙂
BR
Armend
Create your free account or log in to subscribe to the board - and gain access to more than 10,000+ support articles along with insights from experts and peers.