我正在编写一个自定义 ServiceBehavior,它希望我知道请求消息的类型,以推断消息是否用自定义属性装饰。
我的示例合同可能如下所示:
[DataContract]
[Auditable]
public class CompositeType
{
bool boolValue = true;
string stringValue = "Hello ";
[DataMember]
[Audit]
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
}
[DataMember]
[Audit]
public string StringValue
{
get { return stringValue; }
set { stringValue = value; }
}
}
我试图通过使用来识别行为方面的自定义属性:
public object AfterReceiveRequest(ref Message request, IClientChannel channel,
InstanceContext instanceContext)
{
var typeOfRequest = request.GetType();
if (!typeOfRequest.GetCustomAttributes(typeof (AuditableAttribute), false).Any())
{
return null;
}
}
但是typeOfRequest总是作为{Name = "BufferedMessage" FullName = "System.ServiceModel.Channels.BufferedMessage"}
有没有办法可以通过使用请求来推断消息的类型?
注意:我直接引用了包含合同的程序集,并且服务不是通过 wsdl 引用的。