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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:18:16+00:00 2026-06-03T06:18:16+00:00

Is it possible to change the data of incoming HTTP request in WCF? I’ve

  • 0

Is it possible to change the data of incoming HTTP request in WCF?

I’ve already found out how to change HTTP method (using IDispatchOperationSelector and HttpRequestMessageProperty of the incoming message).

I’m writing behavior that would enable to make “POST” requests using GET requests (with method and data stored in query string). I can override the HTTP method, but I can’t find the solution to override the data. I need to load the data stored in query string and use them as HTTP body.

Any thoughts?

  • 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-03T06:18:18+00:00Added an answer on June 3, 2026 at 6:18 am

    You’ll need to recreate the incoming message so that the message body contains the information you want to pass. The body will likely be in either XML or JSON format (supported out-of-the-box). The code below shows one example of how this can be done.

    public class StackOverflow_10391354
    {
        [ServiceContract]
        public class Service
        {
            [WebInvoke(BodyStyle = WebMessageBodyStyle.WrappedRequest)]
            public int Add(int x, int y)
            {
                return x + y;
            }
        }
        class MyWebHttpBehavior : WebHttpBehavior
        {
            protected override WebHttpDispatchOperationSelector GetOperationSelector(ServiceEndpoint endpoint)
            {
                return new MyOperationSelector();
            }
            public override void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
            {
                base.ApplyDispatchBehavior(endpoint, endpointDispatcher);
            }
        }
        class MyOperationSelector : WebHttpDispatchOperationSelector
        {
            protected override string SelectOperation(ref Message message, out bool uriMatched)
            {
                HttpRequestMessageProperty prop = (HttpRequestMessageProperty)message.Properties[HttpRequestMessageProperty.Name];
                if (message.Headers.To.LocalPath.EndsWith("/Add") && prop.Method == "GET")
                {
                    prop.Method = "POST";
                    uriMatched = true;
                    message = CreateBodyMessage(message);
                    return "Add";
                }
                else
                {
                    return base.SelectOperation(ref message, out uriMatched);
                }
            }
    
            private Message CreateBodyMessage(Message message)
            {
                HttpRequestMessageProperty prop = message.Properties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;
                string queryString = prop.QueryString;
                NameValueCollection nvc = HttpUtility.ParseQueryString(queryString);
                StringBuilder sb = new StringBuilder();
                sb.Append('{');
                bool first = true;
                foreach (string key in nvc.Keys)
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        sb.Append(',');
                    }
    
                    sb.Append('\"');
                    sb.Append(key);
                    sb.Append("\":\"");
                    sb.Append(nvc[key]);
                    sb.Append('\"');
                }
                sb.Append('}');
                string json = sb.ToString();
                XmlDictionaryReader jsonReader = JsonReaderWriterFactory.CreateJsonReader(Encoding.UTF8.GetBytes(json), XmlDictionaryReaderQuotas.Max);
                Message result = Message.CreateMessage(MessageVersion.None, null, jsonReader);
                result.Properties.Add(HttpRequestMessageProperty.Name, prop);
                result.Properties.Add(WebBodyFormatMessageProperty.Name, new WebBodyFormatMessageProperty(WebContentFormat.Json));
                result.Headers.To = message.Headers.To;
                return result;
            }
        }
        public static void Test()
        {
            string baseAddress = "http://" + Environment.MachineName + ":8000/Service";
            ServiceHost host = new ServiceHost(typeof(Service), new Uri(baseAddress));
            ServiceEndpoint endpoint = host.AddServiceEndpoint(typeof(Service), new WebHttpBinding(), "");
            endpoint.Behaviors.Add(new MyWebHttpBehavior());
            host.Open();
            Console.WriteLine("Host opened");
    
            WebClient c = new WebClient();
            Console.WriteLine(c.DownloadString(baseAddress + "/Add?x=66&y=88"));
    
            Console.Write("Press ENTER to close the host");
            Console.ReadLine();
            host.Close();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to change the data directory of MySQL using java? regards Shihab
Is it possible to change the font size used in a ContextMenu using the
Is it possible to change the frame title when using \againframe from the Beamer
SQL Server 2008. Is it possible to create Change Data Capture (or Change Tracking)
I am wondering if its possible to change a HTML elements data type with
I'm trying to work out whether it is possible to change the icon based
From apple doc Modifying the Fetch Request I see that is possible to change
Hey I am using a NSURL Connection to receive data. [NSURLConnection sendSynchronousRequest: //create request
I'm using a Derived Column Task to change column data using a CASE WHEN
I know it's possible to change an IP address using a proxy, but I'm

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.