I want to ensure that all our operations that return datasets in our WCF has .ExcludedSchema value set in Property SchemaSerializationMode.
Can I do this with a CustomBehavior? I tried to implement a CustomDispatchBehavior and add a MessageInspector, but the methods AfterReceiveRequest and BeforeSendReply doesn't let me do anything with the return value. In BeforeSendreply, the return value has already been serialized. Where can I plug in my code?
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();
}
}
I solved it using the IParametorInspector
and the inspector looks like this