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 3361434
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:09:07+00:00 2026-05-18T03:09:07+00:00

I am using the new .Net 4.0 RouterService and have a requirement for the

  • 0

I am using the new .Net 4.0 RouterService and have a requirement for the router to log the messages going back and forth. I need to do this by accessing the actual message being routed.

How do I implement a MessageInspector on the Router programatically? Or is there some alternative to using a MessageInspector?

  • 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-18T03:09:08+00:00Added an answer on May 18, 2026 at 3:09 am

    Found the answer:

    internal class MessageLogger : IClientMessageInspector, IDispatchMessageInspector, IEndpointBehavior {
        private readonly ILoggingProvider _Logging;
    
        public MessageLogger(ILoggingProvider logging) {
            _Logging = logging;
        }
    
        #region IDispatchMessageInspector Members
    
        public object BeforeSendRequest(ref Message request, IClientChannel channel) {
            _Logging.LogMessage("Routing message to service");
            return null;
        }
    
        public void AfterReceiveReply(ref Message reply, object correlationState) {
            _Logging.LogMessage("Response from service received");
        }
    
        #endregion
    
    
        #region IDispatchMessageInspector Members
    
        public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext) {
            _Logging.LogMessage("Message received from client");
    
            return null;
        }
    
        public void BeforeSendReply(ref Message reply, object correlationState) {
            _Logging.LogMessage("Sending response to client");
        }
    
        #endregion
    
        #region IEndpointBehavior Members
    
        public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters) {
            return;
        }
    
        public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime) {
            clientRuntime.MessageInspectors.Add(this);
        }
    
        public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher) {
            endpointDispatcher.DispatchRuntime.MessageInspectors.Add(this);
        }
    
        public void Validate(ServiceEndpoint endpoint) { return; }
    
        #endregion
    }
    

    Then hookup to the router endpoint like so:

    public class RouterServiceHost : ServiceHost {
        ...
        public RouterServiceHost() {
            ...
            var endpoint = this.AddServiceEndpoint(routerContract, routerBinding, routerAddress);
            endpoint.Behaviors.Add(new MessageLogger(_Logging));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the new ASP.NET Universal Providers as described at this Hanselman blog post
I am using GIT with a new ASP.NET MVC project. I have a line
I am using the new .NET 3.0 DataContractSerializer. I have both Nullable< > and
I have a rather simple setup here using the new ASP.Net 4.5 in a
ADO.NET has the notorious DataRow class which you cannot instantiate using new. This is
I still new using Asp.net with vb.net Protected Sub login_Click(ByVal sender As Object, ByVal
I created a new ASP.NET website using Visual Web Developer 2008 Express edition and
I'm trying to start a new ASP.NET Web Application Project using Visual Studio 2008.
I am new In ASP.NET, I want to create to Login Form using Membership
I'm planning to design simple website using ASP.NET MVC new technology. Many concepts are

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.