public static void AddFaultDescription(Receive activity, OperationDescription operation) { if (activity.HasFault) { foreach (SendReply sendFault in activity.FollowingFaults) { string action = null; Type type = null; action = sendFault.Action; SendMessageContent sendReply = sendFault.InternalContent as SendMessageContent; if (sendReply != null) { type = sendReply.InternalDeclaredMessageType; } else { SendParametersContent sendReplyParameters = sendFault.InternalContent as SendParametersContent; if (sendReplyParameters != null) { type = sendReplyParameters.ArgumentTypes[0]; // Exception should be the only parameter in SendFault } } Fx.Assert(type != null, "Exception type cannot be null!"); if (type.IsGenericType && type.GetGenericTypeDefinition() == FaultExceptionType) { Type faultType = type.GetGenericArguments()[0]; bool exists = false; // We expect the number of fault types to be small, so we use iterative comparison foreach (FaultDescription faultDescription in operation.Faults) { if (faultDescription.DetailType == faultType) { if (faultDescription.Action != action) { throw FxTrace.Exception.AsError(new ValidationException(SR.SendRepliesHaveSameFaultTypeDifferentAction)); } else { exists = true; break; } } } if (!exists) { FaultDescription faultDescription = MessageBuilder.CreateFaultDescription(operation, faultType, action); operation.Faults.Add(faultDescription); } } } } }
public static void AddFaultDescription(Receive activity, OperationDescription operation) { if (activity.HasFault) { foreach (SendReply reply in activity.FollowingFaults) { string overridingAction = null; System.Type internalDeclaredMessageType = null; overridingAction = reply.Action; SendMessageContent internalContent = reply.InternalContent as SendMessageContent; if (internalContent != null) { internalDeclaredMessageType = internalContent.InternalDeclaredMessageType; } else { SendParametersContent content2 = reply.InternalContent as SendParametersContent; if (content2 != null) { internalDeclaredMessageType = content2.ArgumentTypes[0]; } } if (internalDeclaredMessageType.IsGenericType && (internalDeclaredMessageType.GetGenericTypeDefinition() == FaultExceptionType)) { System.Type faultType = internalDeclaredMessageType.GetGenericArguments()[0]; bool flag = false; foreach (FaultDescription description in operation.Faults) { if (description.DetailType == faultType) { if (description.Action != overridingAction) { throw System.ServiceModel.Activities.FxTrace.Exception.AsError(new ValidationException(System.ServiceModel.Activities.SR.SendRepliesHaveSameFaultTypeDifferentAction)); } flag = true; break; } } if (!flag) { FaultDescription item = MessageBuilder.CreateFaultDescription(operation, faultType, overridingAction); operation.Faults.Add(item); } } } } }