出于安全考慮,我們在服務器中禁用了 TLS 1.0 和 TLS 1.1,并啟用了 TLS 1.2 當我們使用 WCFTestClient 呼叫 WCF Web 服務時,我們會收到以下錯誤訊息。我嘗試了很多方法來修復但沒有任何效果(請參閱:- https://docs.microsoft.com/en-us/dotnet/framework/network-programming/tls#configuring-security-via-appcontext-switches)
我在一篇文章中發現了 WCFTestClient 的問題,但不確定。(https://developercommunity.visualstudio.com/t/wcf-test-client-does-not-support-tls-12/1193549)任何人都可以幫忙
接收對https://devseatm07.europe.shell.com/EventCollectorService/v3.svc的 HTTP 回應時出錯。這可能是由于服務端點系結未使用 HTTP 協議。這也可能是由于服務器中止了 HTTP 請求背景關系(可能是由于服務關閉)。有關更多詳細資訊,請參閱服務器日志。
服務器堆疊跟蹤:
System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage
retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at IEventCollectorService.ReceiveEvent(EventMessage eventMessage)
at EventCollectorServiceClient.ReceiveEvent(EventMessage eventMessage)
Inner Exception:
The underlying connection was closed: An unexpected error occurred on a receive.
at System.Net.HttpWebRequest.GetResponse()
at
System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
Inner Exception:
The client and server cannot communicate, because they do not possess a common algorithm
at System.Net.SSPIWrapper.AcquireCredentialsHandle(SSPIInterface SecModule, String package, CredentialUse intent, SecureCredential scc)
at System.Net.Security.SecureChannel.AcquireCredentialsHandle(CredentialUse credUsage, SecureCredential& secureCredential)
at System.Net.Security.SecureChannel.AcquireCredentialsHandle(CredentialUse credUsage, X509Certificate2 selectedCert, Flags flags)
at System.Net.Security.SecureChannel.AcquireClientCredentials(Byte[]& thumbPrint)
at System.Net.Security.SecureChannel.GenerateToken(Byte[] input, Int32 offset, Int32 count, Byte[]& output)
at System.Net.Security.SecureChannel.NextMessage(Byte[] incoming, Int32 offset, Int32 count)
at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
at System.Net.TlsStream.CallProcessAuthentication(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result)
at System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.ConnectStream.WriteHeaders(Boolean async)
uj5u.com熱心網友回復:
客戶端和服務器無法通信,因為它們沒有通用演算法
此錯誤是由于密碼演算法不匹配導致的,因為在呼叫 API 或服務之前未使用 TLS 1.2 協議。
您可以設定 SecurityProtocol 變數。
您必須做的第一件事是在您的 ASP.NET 專案中添加以下代碼行:
//Add TLS 1.2 to the supported cryptographic protocols
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
如果您的 .NET Framework 版本是 4.5 或更低,或者如果您沒有“Tls12”型別的值,只需使用 int 值,即 3072:
// Add TLS 1.2 to the supported cryptographic protocols (for .NET Framework < 4.5)
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
插入這一行的最佳位置是 Global.asax (ASP.NET 4.x) 或 Startup.cs (ASP.NET 5 / .NET Core) 檔案中的 Application_Start() 方法。
您還可以嘗試其他解決方案:https : //www.ryadel.com/en/asp-net-client-server-cannot-comunicate-because-they-possess-common-algorithm-how-to-fix-c-sharp /
uj5u.com熱心網友回復:
經過長時間的努力,我終于找到了解決辦法。下面的腳本幫助我使用 WCFTestClient 呼叫服務。
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/375513.html
上一篇:c語言中變數的初始化
