protected override void OnWriteBodyContents(XmlDictionaryWriter writer) { // This uses reflection to find the WriteTo method. // For some reason, even though its in the assembly, its not exposed in the .NET Standard API var writeToMethod = _fault.GetType().GetMethod("WriteTo", new[] { typeof(XmlDictionaryWriter), typeof(EnvelopeVersion) }); writeToMethod.Invoke(_fault, new object[] { writer, _messageVersion.Envelope }); }
protected override object GetMessageObject(System.ServiceModel.Channels.Message message) { MessageFault messageFault = MessageFault.CreateFault(message, Int32.MaxValue); Type faultType; if (message.Headers.Action == null) { // todo: check into null action header on unknown fault messages throw new NotImplementedException("empty action"); } else if (_faultTypes.TryGetValue(message.Headers.Action, out faultType)) { MethodInfo m = messageFault.GetType().GetMethod("GetDetail", new Type[] { }).MakeGenericMethod(faultType); return(Activator.CreateInstance(typeof(FaultException <>).MakeGenericType(faultType), m.Invoke(messageFault, null), messageFault.Reason, messageFault.Code)); } else { throw new InvalidOperationException("Unknown action in fault"); } //return _serializers[message.Headers.Action]. .ReadObject(message.GetReaderAtBodyContents()); }