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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:44:30+00:00 2026-05-21T11:44:30+00:00

I have a WCF service that returns JSON to the clients. This is the

  • 0

I have a WCF service that returns JSON to the clients.

This is the app.config

  <system.serviceModel>
<services>
  <service name="MyServices.MyService">
    <endpoint address="" behaviorConfiguration="JsonBehavior" binding="webHttpBinding"
      contract="Myervices.IMyervice">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8732/Design_Time_Addresses/MyEmulator/Service1/" />
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <serviceMetadata httpGetEnabled="True"/>
      <serviceDebug includeExceptionDetailInFaults="True"/>
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="JsonBehavior">
      <webHttp />
    </behavior>
  </endpointBehaviors>
</behaviors>

This is a sample opertaion exposed by the service

 [OperationContract]
    [WebInvoke(BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, Method = "GET", UriTemplate = "me/{id}")]
    JsonObject GetObject(string id, string connection_type);

Now, I would like to log every request that the service receives from clients and response that is being sent back to clients…in this case it sin JSOn.

I have create a custom MessageInspector as follows

public class MyMessageInspector : IDispatchMessageInspector
{
    private bool LoggingEnabled;
    #region IDispatchMessageInspector Members

    public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel, System.ServiceModel.InstanceContext instanceContext)
    {
        Guid correlationState = Guid.NewGuid();
        if (this.LoggingEnabled)
        {
            StringBuilder message = new StringBuilder();
            message.AppendFormat("CorrelationState = {0}{1}", correlationState, Environment.NewLine);
            message.AppendFormat("Local Address = {0}{1}", channel.LocalAddress, Environment.NewLine);
            message.AppendFormat("Remote Address = {0}{1}", channel.RemoteAddress, Environment.NewLine);
            message.AppendLine("Request");
            message.AppendLine(request.ToString());
            message.AppendLine();
            this.logger.LogMessage(message.ToString());
        }

        return correlationState;
    }

    public void BeforeSendReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
    {
        if (this.LoggingEnabled)
        {
            StringBuilder message = new StringBuilder();
            message.AppendFormat("CorrelationState = {0}{1}", correlationState, Environment.NewLine);
            message.AppendLine("Reply");
            message.AppendLine(reply.ToString());
            message.AppendLine();
            this.logger.LogMessage(message.ToString());
        }
    }

    #endregion
}

But this doesnt seem to log any of the resposne.. the response.Tostring() only says “…stream”

the Above works if my service returns data in SOAP XML format..but i want it to log JSON response which is the text inside the *.js file downloaded in the browser when i call the REST service endpoint. ex: http://localhost:8080/MyService/me/2/

any ideas how I can achieve this?

  • 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-21T11:44:30+00:00Added an answer on May 21, 2026 at 11:44 am

    This code provides a mechanism for working with REST messages, and as a bonus allows SOAP to pass through as normal. It’s a little intrusive (the stream is destroyed by reading so the code needs to regenerate it) but I haven’t found any better way.

    http://code.msdn.microsoft.com/WCF-REST-Message-Inspector-c4b6790b

    • 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 returns JSON data back to an app
I have a WCF service that returns some JSON from a serialized object: public
I have a WCF rest service using webHttpBinding that returns JSON result. The problem
I’m writing a WCF service that returns data in JSON format to clients. I
I have code that calls a WCF service and returns a JSON string to
I have created a WCF REST service that returns JSON, but the properties in
I have a WCF Service that return a json. I want to test it
plz help, I'm stuck. I have a WCF service which returns something like this:
I have created an Ajax enabled WCF web service that contains this simple method:
I have the following code in a WCF Service that returns a string, and

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.