title: Creating a MessageContract type using inheritance hierarchy in WCF
body: <p>I am developing a web servic e using .NET WCF. I am using a mesaging service style like this:</p>
  
  <pre><code>[ServiceContract]
  public interface IMyService {
     [OperationContract]
     MyMessageResponse MyOperation(MyMessageRequest msg);
  }
  </code></pre>
  
  <p>Well, I want to apply the <code>MessageContractAttribute</code> to <code>MyMessageResponse</code> and <code>MyMessageRequest</code> because I need to tune SOAP in my own way.</p>
  
  <p>Well, the problem is that <code>MyMessageResponse</code> and <code>MyMessageRequest</code> are part of a hierarchy (I have many service operations and, so, many message types).</p>
  
  <p>Suppose my hierarchy to be this one (class inheritance pseudocode):</p>
  
  <pre><code>MyMessage &lt;- MyMessageFamily1 &lt;- MyMessageRequest
  MyMessage &lt;- MyMessageFamily1 &lt;- MyMessageResponse
  MyMessage &lt;- MyMessageFamily2 &lt;- MyOtherMessageRequest
  MyMessage &lt;- MyMessageFamily2 &lt;- MyOtherMessageResponse
  </code></pre>
  
  <p>I would like to apply <code>MessageContractAttribute</code> to <code>MyMessage</code>, then to <code>MyMessageFamily1</code> and then to <code>MyMessageRequest</code> and to <code>MyMessageResponse</code> (so for the others) like this:</p>
  
  <pre><code>[MessageContract(...)]
  public class MyMessage {
     [MessageBodyMember(...)]
     public MyType1 Member1; /* MyType1 has a DataContract applied */
     [MessageBodyMember(...)]
     public MyType2 Member2; /* MyType2 has a DataContract applied */
  }
  
  [MessageContract(...)]
  public class MyMessageFamily1 : MyMessage {
     [MessageBodyMember(...)]
     public MyType3 MemberFamily11; /* MyType3 has a DataContract applied */
     [MessageBodyMember(...)]
     public MyType3 MemberFamily12; 
  }
  
  [MessageContract(...)]
  public class MyMessageFamily2 : MyMessage {
     [MessageBodyMember(...)]
     public MyType3 MemberFamily21; /* MyType3 has a DataContract applied */
     [MessageBodyMember(...)]
     public MyType3 MemberFamily22; 
  }
  
  [MessageContract(...)]
  public class MyMessageRequest : MyMessageFamily1 {
     [MessageBodyMember(...)]
     public MyType4 MemberRequest1; /* MyType4 has a DataContract applied */
     [MessageBodyMember(...)]
     public MyType4 MemberRequest2; 
  }
  
  [MessageContract(...)]
  public class MyMessageResponse : MyMessageFamily1 {
     [MessageBodyMember(...)]
     public MyType4 MemberResponse1; 
     [MessageBodyMember(...)]
     public MyType4 MemberResponse2; 
  }
  
  [MessageContract(...)]
  public class MyOtherMessageRequest : MyMessageFamily2 {
     [MessageBodyMember(...)]
     public MyType5 MemberRequest1; /* MyType5 has a DataContract applied */
     [MessageBodyMember(...)]
     public MyType5 MemberRequest2; 
  }
  
  [MessageContract(...)]
  public class MyOtherMessageResponse : MyMessageFamily2 {
     [MessageBodyMember(...)]
     public MyType5 MemberResponse1; 
     [MessageBodyMember(...)]
     public MyType5 MemberResponse2; 
  }
  </code></pre>
  
  <p>Problem: <code>MessageContractAttribute</code> is an attribute tat can be inherited, but <code>MessageBodyMemberAttribute</code> and <code>MessageHeaderAttribute</code> do not inherit because of their definition.</p>
  
  <p>The problem is that I want to create a service implementing <code>IMyService</code>.
  <code>IMyService</code> has <code>MyOperation</code> that uses <code>MyMessageResponse</code> and <code>MyMessageRequest</code>.
  But <code>MyMessageResponse</code> should inherit <code>MemberFamily11</code>, <code>MemberFamily12</code>, <code>Member1</code> and <code>Member2</code> and treat them in the soap message in order to place these in the body of the soap message. But the <code>MessageBodyMemberAttribute</code> is not inherited...</p>
  
  <p>How can I solve this problem?</p>