Targetting WCF Web Api Message Handler at specific requests

524 Views Asked by At

Is it possible to target DelegatingHandlers (message handlers) in WCF Web Api at specific requests (as is possible with an operation handler) or are message handlers global. By that I mean they are called for every request.

1

There are 1 best solutions below

0
On BEST ANSWER

You could set up different configurations and map those configurations to the appropriate routes. So for example:

var config1 = new HttpConfiguration();
config1.MessageHandlers.Add(typeof(MyMessageHandler));
config1.MessageHandlers.Add(typeof(MyMessageHandler2));

var config2 = new HttpConfiguration();
config2.MessageHandlers.Add(typeof(MyMessageHandler3));
config2.MessageHandlers.Add(typeof(MyMessageHandler4));

RouteTable.Routes.MapServiceRoute<ContactService>("api/contacts", config1);
RouteTable.Routes.MapServiceRoute<InvoiceService>("api/invoices", config2);