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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:43:22+00:00 2026-05-23T04:43:22+00:00

Using the WCF Web API how would I go about changing a response’s content

  • 0

Using the WCF Web API how would I go about changing a response’s content body after the application logic has been run but before it’s returned to the user. The goal is if suppressstatuscontent is true we:

  • Add a statuscode field to the content body
  • Change the statuscode on the response to 200

I have overridden a DelegatingChannel and in the SendAsnyc have some code that looks like this:

protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
   return base.SendAsync(request, cancellationToken).ContinueWith<HttpResponseMessage>(task =>
   {
      var response = task.Result;

      if (CheckIfRequestHadSuppressStatusCode(request) == true)
      {
         string newResponse = (response.Content == null) ? "" : response.Content.ReadAsString();
         newResponse = "<body>" +newResponse + "</body><statuscode>" + response.StatusCode + "</statuscode>";
         response.StatusCode = HttpStatusCode.OK;                                 
      }
      return response;
   });

A major problem is this doesn’t handle BOTH, xml and Json. I feel like there must be a much better way to go about the problem as this feels very hacky.

  • 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-23T04:43:23+00:00Added an answer on May 23, 2026 at 4:43 am

    I’m not sure of the right approach but I would try something like this:

    protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
    {
       return base.SendAsync(request, cancellationToken)
          .ContinueWith<HttpResponseMessage>(task =>
          {
             var response = task.Result;
             if (CheckIfRequestHadSuppressStatusCode(request) == true)
             {
                switch(response.Content.Headers.ContentType.MediaType)
                {
                   case "application/xml":
                      response.Content = new XmlWithStatusContent(response.Content)
                      break;
                   case "application/json":
                      response.Content = new JsonWithStatusContent(response.Content)
                      break;
                }
    
                response.StatusCode = HttpStatusCode.OK;                                 
             }
             
             return response;
          });
    }
    

    You can encapsulate the code that adds the extra status code markup in specialized versions of HttpContent (e.g. XmlWithStatusContent and JsonWithStatusContent).

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

Sidebar

Related Questions

The background I'm developing a REST API for a C#.NET web application using WCF.
I have developed a Web service using WCF Service Application. This service application is
I am building a AJAX intensive web application (using ASP.NET, JQuery, and WCF web
I am having problems consuming a WCF web service (PaySimple's v3.00 API) using php
I'm using WCF Web API to create a self-hosted/InProcess REST Service (HttpServiceHost) that the
I am developing a web api using WCF Web Api preview 5. At the
I have been using WCF web services for around about a year now and
Facing an interesting issue when I am using WCF Web API with Hammock and
I am using the WCF Web Api 4.0 framework and am running into the
I have several resources that I'd like to expose using the WCF Web API.

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.