Wednesday, March 27, 2019

how to fix a console app implemented with lower version .net framework cannot comsume a web api developed with higher version of .net host in the Azure?

currently we have app implmented with a .net framework 4.5, it is running fine in the local desktop during the development. however the exceptions had thrown after it deployed to the host server.

"System.AggregateException
  HResult=0x80131500
  Message=One or more errors occurred.
  Source=mscorlib
  StackTrace:
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at DealerETL.Program.Main(String[] args)

Inner Exception 1:
CommunicationException: An error occurred while receiving the HTTP response to http://dax:8080/MicrosoftDynamicsAXAif60/SubDealerQRService/xppservice.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.

Inner Exception 2:
WebException: The underlying connection was closed: An unexpected error occurred on a receive.

Inner Exception 3:
IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.

Inner Exception 4:
SocketException: An existing connection was forcibly closed by the remote host
"

the root cause of this issue stems from the Web Api had been implemented with higher version of .net framework 4.6.2 and the console had been implemented with .net framwork 4.5.

by default the security protocol had been set to the Tls which has value 192.


namespace System.Net
{
    [System.Flags]
    public enum SecurityProtocolType
    {
       Ssl3 = 48,
       Tls = 192,
       Tls11 = 768,
       Tls12 = 3072,
    }
}

after we manually set the security protocol in the code. the issue is fixed.

ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072 |(SecurityProtocolType)768;





No comments:

Post a Comment