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

The Archive Base Latest Questions

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

I have a REST POST method as follows: [WebInvoke(BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Xml,

  • 0

I have a REST POST method as follows:

[WebInvoke(BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Xml, RequestFormat = WebMessageFormat.Xml)]
string GetFromXml(XElement xmlString);

I am trying to do a post operation from my client using the following code:

var client = new RestClient();
client.BaseUrl = "http://localhost/XMLRestService/XmlService.svc";
var request = new RestRequest(Method.POST);
request.Resource = "GetFromXml";
client.AddDefaultHeader("Content-Type", "text/xml");            
request.AddBody(obj, "XMLRestService");            
var response = client.Execute(request);

When i do the above i get a 400 Bad request. I then enabled tracing on the WCF Service. And the stack trace gave me a Unrecognized Message version excpetion that is thrown my the System.ServiceModel.CommunicationException class.

I am unable to post the request successfully. Help appreciated.

  • 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-26T08:07:10+00:00Added an answer on May 26, 2026 at 8:07 am

    I finally found the root cause to the exception. The below code works perfect:

    var client = new RestClient();
    client.BaseUrl = serviceBaseUrl;
    var request = new RestRequest(method){RequestFormat = DataFormat.Xml};
    request.Resource = resourceUrl;
    request.AddParameter("text/xml",requestBody, ParameterType.RequestBody);
    var response = client.Execute(request);
    

    The requestBody being sent as parameter should be a serialized xmlString.

    NOTE: If the composite type exposed on the REST Service is using DataContractSerializer then make sure to generate the requestBody using DataContractSerializer and if uses XmlSerializer then generate the requestBody using XmlSerializer.

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

Sidebar

Related Questions

My WCF REST service method: [WebInvoke(Method = POST, ResponseFormat = WebMessageFormat.Xml)] Metadata[] Extract(Stream stream);
I have a REST web service which exposes 2 methods- [POST method] Client will
I have a WCF-REST service with one method which returns a string: [ServiceContract] public
I have created a REST web service using WCF and use HTTP Post Method.
I have a JSON server (WCF REST) with a JSON POST method that accepts
We have a REST API which clients routinely POST and PUT data to. When
I have basic authentatication working with REST API using curl: curl -X POST -H
We have a given REST interface: POST /calculation <data>abc</data> This calculation can be implemented
I have done raw rest get and post and also could do post in
I have looked at nearly every single WCF Rest PUT/POST issues on SO here

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.