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

  • Home
  • SEARCH
  • 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 7513909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:19:55+00:00 2026-05-30T00:19:55+00:00

I am trying to build a REST & json based WCF service that takes

  • 0

I am trying to build a REST & json based WCF service that takes a complex type as input. On the client I am trying to consume this service using HttpClient that comes as a part of WCF REST Starter Kit.

Below is my service code:

[WebInvoke(Method = "POST", UriTemplate = "/SendData", BodyStyle = WebMessageBodyStyle.Wrapped)]
public void SendData(List<EditorData> input)
{
//Do something
}

I have used other options that could be found in the WebMessageBodyStyle enum to no avail.

Here is my complex type data contract which I am using in my client as well:

public class EditorData
{
    public string key { get; set; }
    public long quesno { get; set; }
    public string quescontent { get; set; }
}

Client code:

List<EditorData> listEditor = new List<EditorData> { new EditorData { key = "key1", quescontent = "qcontent1", quesno = 1},new EditorData { key = "key2", quescontent = "qcontent2", quesno = 2}};
string jsonEditorList = listEditor.ToJSON();
HttpClient client = new HttpClient("http://localhost/RestWcfService/RestService.svc/");
client.DefaultHeaders.Accept.Add("application/json");
HttpResponseMessage response = null;
response = client.Post("SendData", HttpContent.Create(jsonEditorList));
response.EnsureStatusIsSuccessful();

To convert my custom object list to json string, I am using the extension method I found here

When I run this application I get the following error:

BadRequest (400) is not one of the following: OK (200), Created (201), Accepted (202), NonAuthoritativeInformation (203), NoContent (204), ResetContent (205), PartialContent (206)

Any thoughts?

EDIT:

Here is the fiddler screenshot:

enter image description here

UPDATE:

As suggested by Jason Freitas, I checked the response in fiddler. This is what is says:

The server encountered an error processing the request. See server logs for more details.

So I went into IIS logs and here is the error logged in IIS:

2012-02-15 13:20:08 fe80::ecdd:d2dd:7f70:bef6%11 POST /RestWcfService/RestService.svc/SendData - 80 - fe80::ecdd:d2dd:7f70:bef6%11 - 400 0 0 0

UPDATE 2

As per Rajesh’s suggestion I enabled tracing for my wcf service. Below is the exception thrown by the server:

The incoming message has an unexpected message format 'Raw'. The expected message formats for the operation are 'Xml', 'Json'. This can be because a WebContentTypeMapper has not been configured on the binding. See the documentation of WebContentTypeMapper for more details.

I still don’t understand how it is getting Raw format when I have specified content type as json.

  • 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-30T00:19:57+00:00Added an answer on May 30, 2026 at 12:19 am

    First try to enable Tracing on your WCF Service to see the exact cause of the 400 bad request error.

    Seems like the input being posted is in a wrong format. You have defined a list of EditorData as a parameter to the method and posting some key value pairs (referring to your fiddler screenshot) Make sure that the json string in fiddler when deserialized gets converted to list of EditorData objects.

    Also you have set the body style to be wrapped. Try to remove that and see if it works. Wrapped requests are used when you have multiple parameters then in that case you wrap all the parameters inside the method name element and send it across the wire.

    UPDATE:

    Please make sure to add the Content-Type to the header as shown below:

    client.DefaultHeaders.ContentType = "application/json";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to build a REST based web service that provides a currency conversion
Hi I'm trying to build up a rest Service which provide JSON response. Yesterday
I'm trying to build a C# service in .NET 3.5 that supports both SOAP
I'm trying to build a JAX-RS based web service using IBM RAD 7.5.5 (which
I'm trying to build a REST api(using Restler) which takes in username and password
I'm trying to build a REST Client usign Async CTP. I'm new to the
I am trying to build an interface that communicates with a REST API for
With the Zend Framework, I am trying to build routes for a REST api
I am trying to build a website with a background image that I want
I am trying to use dependency injection with WCF REST (WebGet) and am having

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.