protected virtual XmlObjectSerializer GetSerializer(Type detailType, string faultExceptionAction, out string action) { action = faultExceptionAction; FaultContractInfo faultInfo = null; for (int i = 0; i < faultContractInfos.Length; i++) { if (faultContractInfos[i].Detail == detailType) { faultInfo = faultContractInfos[i]; break; } } if (faultInfo != null) { if (action == null) { action = faultInfo.Action; } return(faultInfo.Serializer); } else { return(DataContractSerializerDefaults.CreateSerializer(detailType, int.MaxValue /* maxItemsInObjectGraph */)); } }
protected virtual FaultException CreateFaultException(MessageFault messageFault, string action) { IList <FaultContractInfo> faultInfos; if (action != null) { faultInfos = new List <FaultContractInfo>(); for (int i = 0; i < faultContractInfos.Length; i++) { if (faultContractInfos[i].Action == action || faultContractInfos[i].Action == MessageHeaders.WildcardAction) { faultInfos.Add(faultContractInfos[i]); } } } else { faultInfos = faultContractInfos; } Type detailType = null; object detailObj = null; for (int i = 0; i < faultInfos.Count; i++) { FaultContractInfo faultInfo = faultInfos[i]; XmlDictionaryReader detailReader = messageFault.GetReaderAtDetailContents(); XmlObjectSerializer serializer = faultInfo.Serializer; if (serializer.IsStartObject(detailReader)) { detailType = faultInfo.Detail; try { detailObj = serializer.ReadObject(detailReader); FaultException faultException = CreateFaultException(messageFault, action, detailObj, detailType, detailReader); if (faultException != null) { return(faultException); } } catch (SerializationException) { } } } return(new FaultException(messageFault, action)); }
protected virtual FaultException CreateFaultException(MessageFault messageFault, string action) { IList <FaultContractInfo> faultInfos; if (action != null) { faultInfos = new List <FaultContractInfo>(); for (int i = 0; i < _faultContractInfos.Length; i++) { if (_faultContractInfos[i].Action == action || _faultContractInfos[i].Action == MessageHeaders.WildcardAction) { faultInfos.Add(_faultContractInfos[i]); } } } else { faultInfos = _faultContractInfos; } for (int i = 0; i < faultInfos.Count; i++) { FaultContractInfo faultInfo = faultInfos[i]; XmlDictionaryReader detailReader = messageFault.GetReaderAtDetailContents(); XmlObjectSerializer serializer = faultInfo.Serializer; if (serializer.IsStartObject(detailReader)) { Type detailType = faultInfo.Detail; try { object detailObj = serializer.ReadObject(detailReader); FaultException faultException = CreateFaultException(messageFault, action, detailObj, detailType, detailReader); if (faultException != null) { return(faultException); } } #pragma warning disable CA1031 // Do not catch general exception types - return a non-specific FaultException is can't deserializer MessageFault catch (SerializationException) { } #pragma warning restore CA1031 // Do not catch general exception types } } return(new FaultException(messageFault, action)); }