我正在使用.NET WCF开发Web服务。我正在使用这样的消息服务风格:
[ServiceContract]
public interface IMyService {
[OperationContract]
MyMessageResponse MyOperation(MyMessageRequest msg);
}
好吧,我想将MessageContractAttribute
应用于MyMessageResponse
和MyMessageRequest
,因为我需要以自己的方式调整SOAP。
嗯,问题是MyMessageResponse
和MyMessageRequest
是层次结构的一部分(我有很多服务操作,因此有很多消息类型)。
假设我的层次结构是这个(类继承伪代码):
MyMessage <- MyMessageFamily1 <- MyMessageRequest
MyMessage <- MyMessageFamily1 <- MyMessageResponse
MyMessage <- MyMessageFamily2 <- MyOtherMessageRequest
MyMessage <- MyMessageFamily2 <- MyOtherMessageResponse
我想将MessageContractAttribute
应用于MyMessage
,然后应用于MyMessageFamily1
,然后应用于MyMessageRequest
和MyMessageResponse
(以及其他人),就像这样:
[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;
}
问题:MessageContractAttribute
是一个可以继承的属性,但由于其定义,MessageBodyMemberAttribute
和MessageHeaderAttribute
不会继承。
问题是我想创建一个实现IMyService
的服务。
IMyService
MyOperation
MyMessageResponse
使用MyMessageRequest
和MyMessageResponse
。
但是MemberFamily11
应该继承MemberFamily12
,Member1
,Member2
和MessageBodyMemberAttribute
并在soap消息中处理它们,以便将它们放在soap消息的正文中。但{{1}}不是继承的......
我该如何解决这个问题?