Share via


Tip: Peer Channel and custom Message contracts

Scenario: Say, we have defined a custom Message contract to use in our Application like so: 

    public enum SendMessageType

    {

   Send,

        Ack,

        Resend,

    }

    [MessageContract(IsWrapped=false)]

    public class TestMessage

    {

        [MessageHeader]

        public SendMessageType Type;

        [MessageHeader]

        public int MessageId;

    }

   

    [ServiceContract(CallbackContract = typeof(IMessage))]

    public interface IMessage

    {

        [OperationContract(IsOneWay = true)]

         void SendMessage(TestMessage message);

          }

Symptom: Messages are not being received by the peers and the client channels are being torn down due to FaultException when sending messages.

Tip:   Make sure that the TestMessage Message Contract above actually has an explicit constructor defined as well. So the modified TestMessage Message contract looks like:

    [MessageContract(IsWrapped=false)]

    public class TestMessage

    {

        [MessageHeader]

        public SendMessageType Type;

        [MessageHeader]

        public int MessageId;

        public TestMessage()

        {

        }

       }

 

-Shalini.