From 27610b571ab8507ea9dee35051153264ef9b82a3 Mon Sep 17 00:00:00 2001 From: Pr1ynka <106768724+Pr1ynka@users.noreply.github.com> Date: Thu, 9 Nov 2023 11:11:46 +0000 Subject: [PATCH] Enable Data Contract Serialization for Remoting Exceptions (#629) * Enable Data Contract Serialization for Remoting Exceptions * Make updates to the correct files * Add setting during initialization * Proposed change to not break secure remoting * Using TryLoadForm to get default settings * bug fix, add missing semicolon * Update src/Hosting.Services.Remoting/RemotingListenerBuilder.cs * Update src/Services.Remoting/Client/OmexServiceProxyFactory.cs --------- Co-authored-by: Keith Cully <2370032+K-Cully@users.noreply.github.com> --- .../RemotingListenerBuilder.cs | 9 +++++++++ .../Client/OmexServiceProxyFactory.cs | 16 ++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/Hosting.Services.Remoting/RemotingListenerBuilder.cs b/src/Hosting.Services.Remoting/RemotingListenerBuilder.cs index acdb6269..6814a9c8 100644 --- a/src/Hosting.Services.Remoting/RemotingListenerBuilder.cs +++ b/src/Hosting.Services.Remoting/RemotingListenerBuilder.cs @@ -29,6 +29,15 @@ protected RemotingListenerBuilder( string name, FabricTransportRemotingListenerSettings? settings = null) { + if (settings == null) + { + if (!FabricTransportRemotingListenerSettings.TryLoadFrom("TransportSettings", out settings)) + { + settings = new FabricTransportRemotingListenerSettings(); + } + } + + settings.ExceptionSerializationTechnique = FabricTransportRemotingListenerSettings.ExceptionSerialization.Default; Name = name; Settings = settings; } diff --git a/src/Services.Remoting/Client/OmexServiceProxyFactory.cs b/src/Services.Remoting/Client/OmexServiceProxyFactory.cs index f2da766c..948f1114 100644 --- a/src/Services.Remoting/Client/OmexServiceProxyFactory.cs +++ b/src/Services.Remoting/Client/OmexServiceProxyFactory.cs @@ -3,6 +3,7 @@ using Microsoft.ServiceFabric.Services.Remoting.Client; using Microsoft.ServiceFabric.Services.Remoting.FabricTransport; +using Microsoft.ServiceFabric.Services.Remoting.FabricTransport.Runtime; using Microsoft.ServiceFabric.Services.Remoting.V2.FabricTransport.Client; namespace Microsoft.Omex.Extensions.Services.Remoting.Client @@ -20,9 +21,19 @@ namespace Microsoft.Omex.Extensions.Services.Remoting.Client public static class OmexServiceProxyFactory { private static ServiceProxyFactory s_serviceProxyFactory = new(handler => - new OmexServiceRemotingClientFactory( + { + FabricTransportRemotingSettings remotingSettings; + if (!FabricTransportRemotingSettings.TryLoadFrom("TransportSettings", out remotingSettings)) + { + remotingSettings = new FabricTransportRemotingSettings(); + } + + remotingSettings.ExceptionDeserializationTechnique = FabricTransportRemotingSettings.ExceptionDeserialization.Default; + return new OmexServiceRemotingClientFactory( new FabricTransportServiceRemotingClientFactory( - remotingCallbackMessageHandler: handler))); + remotingCallbackMessageHandler: handler, + remotingSettings: remotingSettings)); + }); /// /// Binds custom transport settings to the service proxy factory. @@ -30,6 +41,7 @@ public static class OmexServiceProxyFactory /// public static void WithCustomTransportSettings(FabricTransportRemotingSettings transportSettings) { + transportSettings.ExceptionDeserializationTechnique = FabricTransportRemotingSettings.ExceptionDeserialization.Default; s_serviceProxyFactory = new ServiceProxyFactory(handler => new OmexServiceRemotingClientFactory( new FabricTransportServiceRemotingClientFactory(