Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7897855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:16:31+00:00 2026-06-03T08:16:31+00:00

I need to apply a custom message formatter to all operations within a service.

  • 0

I need to apply a custom message formatter to all operations within a service.

Rather than apply an OperationBehavior manually to all the operations, I am attempting to loop through all operations from within a ServiceBehavior thusly (the details of my serializer aren’t important, just that it implements IDispatchMessageFormatter):

public void ApplyDispatchBehavior(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase) {
    foreach (ChannelDispatcher channelDispatcher in serviceHostBase.ChannelDispatchers) {
        foreach (EndpointDispatcher endpointDispatcher in channelDispatcher.Endpoints.Where(e => !e.IsSystemEndpoint)) {
            foreach (DispatchOperation dispatchOperation in endpointDispatcher.DispatchRuntime.Operations) {
                LoggedOperationSerializer serializer = new LoggedOperationSerializer(dispatchOperation.Formatter);
                dispatchOperation.Formatter = serializer;
            }
        }
    }
}

The serializer seems to get set fine, with no errors. However, the DeserializeRequest method on LoggedOperationSerializer is never hit when I set a breakpoint and debug.

If instead I apply the formatter inside an OperationBehavior like this:

public void ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispatchOperation) {
    LoggedOperationSerializer serializer = new LoggedOperationSerializer(dispatchOperation.Formatter);
    dispatchOperation.Formatter = serializer;
}

then the DeserializeRequest method is hit as expected.

If I apply both a ServiceBehvior and an OperationBehavior as shown and attach a debugger, as expected, the first code block shown is hit first, iterating through all operations on the service, and the formatter is set. However, by the time that the ApplyDispatchBehavior for the OperationBehavior is hit, the formatter set above has “fallen off”, and has been replaced by the default CompositeDispatchFormatter.

I really don’t want to have to apply an OperationBehavior manually to all operations to get this to work… any ideas on why what might be happening?

This is using WebHttpBinding in case that is at all relevant, I don’t know why it would be though.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T08:16:33+00:00Added an answer on June 3, 2026 at 8:16 am

    If you’re using WebHttpBinding, I’m assuming you’re also using the WebHttpBehavior in your endpoint. If so, then the WebHttpBehavior is overriding the formatter you added in your service behavior.

    For all behaviors in WCF, when ApplyDispatchBehavior is called, it’s called in the following order: Service behaviors, contract behaviors, endpoint behaviors, operation behaviors (which explains why when you use an operation behavior it works). The WebHttpBehavior will set its formatter to deal with things such understanding JSON inputs, mapping to URI templates, etc.

    If you don’t want to add operation behaviors to all the operations in your services, you can either use an endpoint behavior, added after the WebHttpBehavior in your endpoint, or an endpoint derived from WebHttpBehavior where you only override ApplyDispatchBehavior, first calling the base implementation, then you loop through all the operations in the contract to set your LoggedOperationSerializer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a service using Thrift and need to apply some tests to ensure
I have a gwt application which I need to apply custom themes for specific
I need to apply custom style to datepicker. I found http://www.themeroller.com/ but the output
I need to apply a custom style to my datepicker but can't work out
I need to load a page into a webview and then apply some custom
I need to apply an Aero background blur to only part of a custom-shaped
I need to apply some xml templates to various streams of xml data (and
I need to apply a style in code ike this: TextBlock.Style = TryFindResource(MyStyle) as
I need to apply validation on input time intervals that are taken in as
I need to apply paragraph formatting to a selection in a rich text box.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.