Search code examples
.netwcfunit-testingsoapfault

WCF Message.IsFault


I am trying to write a test and need to create a Message object with the IsFault property set to true. However, this property only has a getter. Does anyone know the best way to create a message where this property would be set to true?

Thanks


Solution

  • Use the Message.CreateMessage() overload that accepts a MessageFault object. Something like the following should work.

    Message CreateMessage()
    {
        return Message.CreateMessage(
            MessageVersion.Default,
            MessageFault.CreateFault(new FaultCode("fault-string"), "reason"),
            "action-string");
    }