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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:58:35+00:00 2026-06-02T12:58:35+00:00

I have a WCF service with several methods. I would like to log the

  • 0

I have a WCF service with several methods. I would like to log the raw request that came in from the client regardless of how this was sent. One method accepts the data as a querystring (strictly for legacy support) which I can log using:

OperationContext.Current.IncomingMessageHeaders.To.AbsoluteUri

That is sufficient in that scenario, but other methods allow the client to send data as XML using a proxy class generated by svcutil.exe. In this scenario I have found the data I want in the s:Body of:

OperationContext.Current.RequestContext.RequestMessage

Unfortunately, no matter what I try I can’t create a buffered copy of the message before it is read. Here is an example:

public CascadeResponse SendCustomer(Customer c)
    {
        Message msg = OperationContext.Current.RequestContext.RequestMessage.CreateBufferedCopy(Int32.MaxValue).CreateMessage();
        LogMessage(msg);
        // Now that the request is logged, get on with the rest
    }

On the first line of SendCustomer, however, I get the following error:

This message cannot support the operation because it has been read.

This is the point of me creating the buffered copy, surely? I’m guessing that I’m doing something elementally wrong here.

Edit:

Ok, so the method is now like this:

public CascadeResponse SendCustomer(Message requestMessage)
    {
        Message msg = OperationContext.Current.RequestContext.RequestMessage.CreateBufferedCopy(Int32.MaxValue).CreateMessage();
        LogMessage(msg);
        // Now that the request is logged, get on with the rest        
        Customer c = msg.GetBody<Customer>();
        string clientKey = "1111"; // This should be the clientKey string passed to the function along with the customer 
        return SendLead(c, clientKey);
    }

My problem is that I don’t know how to get the Customer and ClientKey sent as separate entities. I could make clientKey a property of Customer (or create a custom object that is specifically for passing data in and contains Customer and ClientKey as attributes), but I would like to avoid that if possible, as this is an upgrade of a legacy system that already works this way.

I am also having trouble using svcUtil.exe to create my proxy classes – I assume that having the above method signature means my service will no longer advertise the correct signature to send requests as? Not sure if that is clear enough – if my only input method accepts a Message object, how does my client know to send a Customer and a ClientKey?

  • 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-02T12:58:45+00:00Added an answer on June 2, 2026 at 12:58 pm

    I found a solution that others might also find useful. Creating a MessageInspector allows you to attach code to the “AfterReceiveRequest” and “BeforeSendReply” events, as per the following:

    public class MessageInspector : IDispatchMessageInspector
    {
        public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
        {
            MessageBuffer buffer = request.CreateBufferedCopy(Int32.MaxValue);
            request = buffer.CreateMessage();
            LogMessage("Received:\n{0}", buffer.CreateMessage().ToString());
            return null;
        }
    
        public void BeforeSendReply(ref Message reply, object correlationState)
        {
            MessageBuffer buffer = reply.CreateBufferedCopy(Int32.MaxValue);
            reply = buffer.CreateMessage();
            LogMessage("Sending:\n{0}", buffer.CreateMessage().ToString());
        }
    }
    

    There is a full tutorial for setting up message inspectors fo wcf here. I will say be careful to check your fully qualified assembly name when you are adding the behavior extension to your app.config/web.config.

    Hope someone else finds this useful.

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

Sidebar

Related Questions

I have a WCF web service that exposes several business methods. I also have
My program is a WCF service which publishes several methods and have multiple client.
I have a WCF service that I have to reference from a .net 2.0
I have a WCF Service that maintains several connections to various databases. I am
I have a WCF service that can receive several requests/minute (or seconds) that need
I have an IIS-Hosted WCF service and would like to make it available at
I have a WCF service, hosted in IIS 7.0 that needs to run database
I have a WCF Service that should not enter the faulted state. If there's
We have a C# client app that communicates to our C# backend service via
I have WCF service that is hosted in IIS . I need to initialize

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.