diff --git a/UaClient/ServiceModel/Ua/Channels/ClientSecureChannel.cs b/UaClient/ServiceModel/Ua/Channels/ClientSecureChannel.cs index 9566c25..c2e09d9 100644 --- a/UaClient/ServiceModel/Ua/Channels/ClientSecureChannel.cs +++ b/UaClient/ServiceModel/Ua/Channels/ClientSecureChannel.cs @@ -315,6 +315,11 @@ private async Task SendRequestAsync(ServiceOperation operation, CancellationToke { _sendingSemaphore.Release(); } + } + + private RecyclableMemoryStream GetRecyclableMemoryStreams(string tag) + { + return new RecyclableMemoryStream(_streamManager, tag); } /// @@ -325,7 +330,7 @@ private async Task SendRequestAsync(ServiceOperation operation, CancellationToke /// A representing the asynchronous operation. private async Task SendOpenSecureChannelRequestAsync(OpenSecureChannelRequest request, CancellationToken token) { - var bodyStream = _streamManager.GetStream("SendOpenSecureChannelRequestAsync"); + var bodyStream = GetRecyclableMemoryStreams("SendOpenSecureChannelRequestAsync"); using (var bodyEncoder = StackProfile.EncodingProvider.CreateEncoder(bodyStream, this, keepStreamOpen: false)) { bodyEncoder.WriteRequest(request); @@ -344,7 +349,7 @@ private async Task SendOpenSecureChannelRequestAsync(OpenSecureChannelRequest re /// A representing the asynchronous operation. private async Task SendCloseSecureChannelRequestAsync(CloseSecureChannelRequest request, CancellationToken token) { - var bodyStream = _streamManager.GetStream("SendCloseSecureChannelRequestAsync"); + var bodyStream = GetRecyclableMemoryStreams("SendCloseSecureChannelRequestAsync"); using (var bodyEncoder = StackProfile.EncodingProvider.CreateEncoder(bodyStream, this, keepStreamOpen: false)) { bodyEncoder.WriteRequest(request); @@ -363,7 +368,7 @@ private async Task SendCloseSecureChannelRequestAsync(CloseSecureChannelRequest /// A representing the asynchronous operation. private async Task SendServiceRequestAsync(IServiceRequest request, CancellationToken token) { - var bodyStream = _streamManager.GetStream("SendServiceRequestAsync"); + var bodyStream = GetRecyclableMemoryStreams("SendServiceRequestAsync"); using (var bodyEncoder = StackProfile.EncodingProvider.CreateEncoder(bodyStream, this, keepStreamOpen: false)) { bodyEncoder.WriteRequest(request); @@ -463,7 +468,7 @@ private async Task ReceiveResponsesAsync(CancellationToken token = default) token.ThrowIfCancellationRequested(); ThrowIfClosedOrNotOpening(); - var bodyStream = _streamManager.GetStream("ReceiveResponseAsync"); + var bodyStream = GetRecyclableMemoryStreams("ReceiveResponseAsync"); using (var bodyDecoder = StackProfile.EncodingProvider.CreateDecoder(bodyStream, this, keepStreamOpen: false)) { var ret = await _conversation!.DecryptMessageAsync(bodyStream, ReceiveAsync, token).ConfigureAwait(false); diff --git a/UaClient/Workstation.UaClient.csproj b/UaClient/Workstation.UaClient.csproj index 72fce77..bdba859 100644 --- a/UaClient/Workstation.UaClient.csproj +++ b/UaClient/Workstation.UaClient.csproj @@ -40,7 +40,7 @@ - +