public static async Task <TReply?> DispatchAsync <TReply>(this Dispatcher.DispatcherClient dispatcherClient, object content) { var request = new RequestEnvelope { CorrelationId = Guid.NewGuid().ToString(), Type = content.GetType().AssemblyQualifiedName, Data = UnsafeByteOperations.UnsafeWrap(JsonSerializer.SerializeToUtf8Bytes(content)) }; var response = await dispatcherClient.DispatchAsync(request, new CallOptions(deadline : DateTime.UtcNow.AddSeconds(118), headers : new Metadata())); if (response.Error) { var errorType = Type.GetType(response.ErrorType, an => Assembly.Load(an.Name ?? null !), null, false, true); var exception = errorType != null ? (Exception)(Activator.CreateInstance(errorType, response.ErrorMessage) ?? null !) : new Exception(response.ErrorMessage); throw exception; //var serializer = new System.Runtime.Serialization.DataContractSerializer(errorType); //using var ms = new MemoryStream(response.Data.ToByteArray()); //ms.Position = 0; //var reader = XmlDictionaryReader.CreateTextReader(ms, XmlDictionaryReaderQuotas.Max); //var exception = (Exception)(serializer.ReadObject(reader) ?? null!); //throw exception; } else { if (response.Empty || string.IsNullOrEmpty(response.Type)) { return(default);
public static async Task <TReply> DispatchAsync <TReply>(this Dispatcher.DispatcherClient dispatcherClient, object content) { var request = new RequestEnvelope { CorrelationId = Guid.NewGuid().ToString(), Type = content.GetType().AssemblyQualifiedName, Content = Value.Parser.ParseJson(JsonSerializer.Serialize(content)) }; var response = await dispatcherClient.DispatchAsync(request); if (response.Empty) { return(default);
public static async Task <TReply?> DispatchAsync <TReply>(this Dispatcher.DispatcherClient dispatcherClient, object content) { var request = new RequestEnvelope { CorrelationId = Guid.NewGuid().ToString(), Type = content.GetType().AssemblyQualifiedName, Content = Value.Parser.ParseJson(JsonSerializer.Serialize(content)) }; var response = await dispatcherClient.DispatchAsync(request); if (response.Error) { throw new ServerException(response.CorrelationId, response.ErrorType, response.ErrorMessage, response.ErrorDetails); } if (response.Empty || string.IsNullOrEmpty(response.Type)) { return(default);
public MessagingClient(Dispatcher.DispatcherClient dispatcherClient, ILogger <MessagingClient> logger) { this.dispatcherClient = dispatcherClient; this.logger = logger; }