我想确保在 WCF 中返回数据集的所有操作都在 Property SchemaSerializationMode 中设置了 .ExcludedSchema 值。
我可以用 CustomBehavior 做到这一点吗?我试图实现一个 CustomDispatchBehavior 并添加一个 MessageInspector,但是 AfterReceiveRequest 和 BeforeSendReply 方法不允许我对返回值做任何事情。在 BeforeSendreply 中,返回值已经被序列化了。我在哪里可以插入我的代码?
public class CustomDispatchBehavior : BehaviorExtensionElement, IServiceBehavior
{
public override Type BehaviorType
{
get { return typeof(CustomDispatchBehavior); }
}
protected override object CreateBehavior()
{
return new CustomDispatchBehavior();
}
void IServiceBehavior.AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, System.Collections.ObjectModel.Collection<ServiceEndpoint> endpoints, BindingParameterCollection bindingParameters)
{
//throw new NotImplementedException();
}
void IServiceBehavior.ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
{
//throw new NotImplementedException();
foreach (ChannelDispatcher chanDisp in serviceHostBase.ChannelDispatchers)
{
foreach (EndpointDispatcher ed in chanDisp.Endpoints)
{
ed.DispatchRuntime.MessageInspectors.Add(new MyMessageInspector());
}
}
}
void IServiceBehavior.Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
{
//throw new NotImplementedException();
}
}