FaultException<MyType> : "The creator of this fault did not specify a reason" error

I have a simple service to return a custom SOAP Fault. And here is what the service throws

MappingError me = new MappingError();

me.ErrorCode = ErrorType.OrderMappingFailed;

me.Message = "Order mapping failed";

throw new FaultException<MappingError>(me);

At this point i get an exception "The creator of this fault did not specify a reason".

Looking around i see there is a FaultReason(String) class and FaultException<> has a readonly Reason property. So, i used one of the overloaded constructor to set the FaultReason and made it work. Here is the working code

MappingError me = new MappingError();

me.ErrorCode = ErrorType.OrderMappingFailed;

me.Message = "Order mapping failed";

FaultException<MappingError> fe = new FaultException<MappingError>(me, new FaultReason("Order Guid is NULL"));

throw fe;

Now, will this be the behaviour when Winfx ships. If that be the case please update the FaultException<> SDK docs.

[ServiceContract]

public interface IMyService

{

[OperationContract]

[FaultContract(typeof(MappingError))]

Guid SendRequest(int ID);

}

[DataContract]

public class MappingError

{

[DataMember]

public ErrorType ErrorCode;

[DataMember]

public String Message;

}




Answer this question

FaultException<MyType> : "The creator of this fault did not specify a reason" error

  • Dave Gurr

    I guess then i don't understand the point in having a constructor like "new FaultException<MyType>(myinstance)" and a readonly Reason property.

    It will be good just to have this constructor " new FaultException<MyType>(myinstance, FaultReason("Myreason"))"

    Anyway, i posted the issue so that SDK docs http://windowssdk.msdn.microsoft.com/en-us/library/ms576199.aspx can be corrected.

    Thanks,

    T.Ramesh.



  • Michael_Shao

    The FaultException is a specific type of exception that allows bubbling up fault information into our stack so that we can map it to a SOAP fault. The code you are showing above does not populate the FaultException with a FaultReason and therefore there is no communicable text for the reason. What you've been filling in is the fault detail, which is in fact a different data item in the SOAP fault.


  • FaultException<MyType> : "The creator of this fault did not specify a reason" error