从 .NET 6/7 更新到 .NET 8 后,我们在尝试使用 nettcp 绑定调用 WCF 端点时遇到此异常。
该参数的值必须为正。 (参数“尺寸”)
实际值为 0。在 System.ServiceModel.Channels.ConnectionUtilities.ValidateBufferBounds(Int32 bufferSize,Int32 偏移量,Int32 大小)
在System.ServiceModel.Channels.SocketConnection.BeginRead(Int32偏移量,Int32大小,TimeSpan超时,Action1回调,对象状态)1 callback, Object state) at System.ServiceModel.Channels.DelegatingConnection.BeginRead(Int32 offset, Int32 size, TimeSpan timeout, Action
在 System.ServiceModel.Channels.ConnectionStream.ReadAsync(Byte[] 缓冲区,Int32 偏移量,Int32 计数,CancellationToken 取消令牌)
在 System.Net.Security.SslStream.EnsureFullTlsFrameAsync[TIOAdapter](CancellationToken取消令牌,Int32预计大小)
在 System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder1.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 令牌)1.StateMachineBox
在 System.Net.Security.SslStream.ReceiveHandshakeFrameAsync[TIOAdapter](CancellationToken CancelToken)
在 System.Net.Security.SslStream.ForceAuthenticationAsync[TIOAdapter](布尔 receiveFirst,Byte[] reAuthenticationData,CancellationToken CancellationToken) 在 System.ServiceModel.Channels.SslStreamSecurityUpgradeInitiator.OnInitiateUpgradeAsync(流流、OutWrapper1 连接Wrapper、ClientFramingDecoder 解码器、IDefaultCommunicationTimeouts defaultTimeouts、TimeSpan 超时) 在 System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.SendPreambleAsync(IConnection 连接,ArraySegment`1 前导码,TimeSpan 超时) 在 System.ServiceModel.Channels.ConnectionPoolHelper.EstablishConnectionAsync(TimeSpan 超时) 在 System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.OnOpenAsync(TimeSpan 超时) 在 System.ServiceModel.Channels.CommunicationObject.OnOpenAsyncInternal(TimeSpan 超时) 在 System.ServiceModel.Channels.CommunicationObject.System.ServiceModel.IAsyncCommunicationObject.OpenAsync(TimeSpan 超时) 在 System.ServiceModel.Channels.ServiceChannel.OnOpenAsync(TimeSpan 超时) 在 System.ServiceModel.Channels.CommunicationObject.OnOpenAsyncInternal(TimeSpan 超时) 在 System.ServiceModel.Channels.CommunicationObject.System.ServiceModel.IAsyncCommunicationObject.OpenAsync(TimeSpan 超时) 在 System.ServiceModel.Channels.CommunicationObject.OpenAsyncInternal(TimeSpan 超时) 在 System.Runtime.TaskHelpers.WaitForCompletion(任务任务) 在 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan 超时) 在System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel通道,TimeSpan超时) 在System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan超时,CallOnceManager级联) 在 System.ServiceModel.Channels.ServiceChannel.EnsureOpened(TimeSpan 超时) 在 System.ServiceModel.Channels.ServiceChannel.Call(字符串操作、布尔单向、ProxyOperationRuntime 操作、Object[] ins、Object[] outs、TimeSpan 超时) 在 System.ServiceModel.Channels.ServiceChannel.Call(字符串操作,布尔单向,ProxyOperationRuntime 操作,Object[] ins,Object[] outs) 在System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(MethodCall方法调用,ProxyOperationRuntime操作) 在 System.ServiceModel.Channels.ServiceChannelProxy.Invoke(MethodInfo targetMethod,Object[] args)1 remoteSecurityWrapper) at System.ServiceModel.Channels.StreamSecurityUpgradeInitiatorBase.InitiateUpgradeAsync(Stream stream) at System.ServiceModel.Channels.ConnectionUpgradeHelper.InitiateUpgradeAsync(StreamUpgradeInitiator upgradeInitiator, OutWrapper
修复方法是将
System.ServiceModel.*
包的引用显式添加到 csproj。
<PackageReference Include="System.ServiceModel.NetTcp" Version="6.2.0" />
<PackageReference Include="System.ServiceModel.Primitives" Version="6.2.0" />
<PackageReference Include="System.ServiceModel.Security" Version="6.0.0" />
这种模式在任何升级的解决方案中都会重复出现。 一个 *.sln 给出了进一步的错误,例如
Identity check failed for outgoing message. The expected DNS identity of the remote endpoint was 'local.system-name' but the remote endpoint provided DNS claim 'local.system-name'.
If this is a legitimate remote endpoint, you can fix the problem by explicitly specifying DNS identity 'local.system-name' as the Identity property of EndpointAddress when creating channel proxy.
是的...它报告的 DNS 与预期和收到的相同。也通过添加这个来修复
<PackageReference Include="System.ServiceModel.Http" Version="6.2.0" />