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

  • Home
  • SEARCH
  • 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 545013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:42:59+00:00 2026-05-13T10:42:59+00:00

I have a custom intranet application that has no interoperability requirements. We programatically construct

  • 0

I have a custom intranet application that has no interoperability requirements. We programatically construct a NetTcp channel in duplex mode for passing messages. We wanted to change the message encoding but haven’t been able to figure out how to make that happen.

The approach we have taken (unsuccessfully) has been to extend the NetTcpBinding into a new class called LeanTcpBinding as follows:


internal class LeanTcpBinding : NetTcpBinding
{
    private static readonly ILog _log =
        LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

    public override BindingElementCollection CreateBindingElements()
    {
        BindingElementCollection bindingElementCollection = base.CreateBindingElements();
        BindingElement encodingElement = bindingElementCollection.FirstOrDefault(
            bindingElement => bindingElement is BinaryMessageEncodingBindingElement);
        if (encodingElement != null)
        {
            int index = bindingElementCollection.IndexOf(encodingElement);
            bindingElementCollection.RemoveAt(index);
            bindingElementCollection.Insert(index, new LeanBinaryMessageEncodingBindingElement());
        }
        else
        {
            _log.Warn("Encoding not found");
        }

        return bindingElementCollection;
    }
}

Obviously, we’re trying to replace the default BinaryMessageEncodingBindingElement with our own. Just to get use started, the LeanBinaryMessageEncodingBindingElement is an extension of the BinaryMessageEncodingBindingElement as follows:


 internal class LeanBinaryMessageEncodingBindingElement : MessageEncodingBindingElement
 {
        private readonly BinaryMessageEncodingBindingElement _bindingElement;

        /// 
        /// Initializes a new instance of the  class.
        /// 
        public LeanBinaryMessageEncodingBindingElement()
        {
            _bindingElement = new BinaryMessageEncodingBindingElement();
        }

        /// 
        /// Initializes a new instance of the  class.
        /// 
        /// The binding element.
        public LeanBinaryMessageEncodingBindingElement(BinaryMessageEncodingBindingElement bindingElement)
        {
            _bindingElement = bindingElement;
        }

        /// 
        /// Initializes a new instance of the  class.
        /// 
        /// The element to be cloned.
        /// The binding element.
        public LeanBinaryMessageEncodingBindingElement(MessageEncodingBindingElement elementToBeCloned, BinaryMessageEncodingBindingElement bindingElement)
            : base(elementToBeCloned)
        {
            _bindingElement = bindingElement;
        }

        /// 
        /// When overridden in a derived class, returns a copy of the binding element object.
        /// 
        /// 
        /// A  object that is a deep clone of the original.
        /// 
        public override BindingElement Clone()
        {
            return new LeanBinaryMessageEncodingBindingElement(
                (BinaryMessageEncodingBindingElement)_bindingElement.Clone());
        }

        /// 
        /// When overridden in a derived class, creates a factory for producing message encoders.
        /// 
        /// 
        /// The  used to produce message encoders.
        /// 
        public override MessageEncoderFactory CreateMessageEncoderFactory()
        {
            return new LeanBinaryMessageEncoderFactory(_bindingElement.CreateMessageEncoderFactory());
        }

        /// 
        /// When overridden in a derived class, gets or sets the message version that can be handled by the message encoders produced by the message encoder factory.
        /// 
        /// 
        /// The  used by the encoders produced by the message encoder factory.
        /// 
        public override MessageVersion MessageVersion
        {
            get { return _bindingElement.MessageVersion; }
            set { _bindingElement.MessageVersion = value; }
        }
 }

When I try to use the binding it does exactly what I think it should do … it replaces the BinaryMessageEncodingBindingElement. However, I never get any calls to the LeanBinaryMessageEncodingBindingElement.CreateMessageEncoderFactory(), even though messages are being exchanged across the channel.

Anyone have any suggestions on how to do this properly?

  • 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-05-13T10:42:59+00:00Added an answer on May 13, 2026 at 10:42 am

    Kenny Wolf clarified what was missing and it’s documented in the blog entry below.

    http://kennyw.com/?p=170

    For the impatient, the problem is that by default the MessageEncoderBindingElement does not add itself to the context’s binding parameters. As a result, when the transport later goes to find the MessageEncoderBindingElement it can not find the one that I (or you) have created and has the silent failure that I noted in my original post.

    Unfortunately, you’ll have to override all of the CanBuildXXX and BuildXXX methods as follows to ensure that you are adding the binding element to the binding parameters of the context.

    
            public override bool CanBuildChannelFactory(BindingContext context)
            {
                if (context == null) {
                    throw new ArgumentNullException("context");
                }
    
                context.BindingParameters.Add(this);
                return context.CanBuildInnerChannelFactory();
            }
    
            public override bool CanBuildChannelListener(BindingContext context)
            {
                if (context == null) {
                    throw new ArgumentNullException("context");
                }
    
                context.BindingParameters.Add(this);
                return context.CanBuildInnerChannelListener();
            }
    
            public override IChannelFactory BuildChannelFactory(BindingContext context)
            {
                if (context == null) {
                    throw new ArgumentNullException("context");
                }
    
                context.BindingParameters.Add(this);
                return context.BuildInnerChannelFactory();
            }
    
            public override IChannelListener BuildChannelListener(BindingContext context)
            {
                if (context == null) {
                    throw new ArgumentNullException("context");
                }
    
                context.BindingParameters.Add(this);
                return context.BuildInnerChannelListener();
            }
    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 291k
  • Answers 291k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you only want to make one pass through the… May 13, 2026 at 5:56 pm
  • Editorial Team
    Editorial Team added an answer You can use the Enumerable.Any method: bool contained = alist.Any(… May 13, 2026 at 5:56 pm
  • Editorial Team
    Editorial Team added an answer If you mean, how do you go back and free… May 13, 2026 at 5:56 pm

Related Questions

We have build a intranet application where users have to login to do certain
I'm having a few problems with an application that integrates sharepoint, SQL reporting services
I have a website that I am working on that has both an intranet
Our company has an intranet with 30,000+ web pages and 160+ web applications. This
We have an intranet asp.net web application which uses the OOTB ASP.net membership and

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.