WCF Restful services POST method error, displays 400 bad request RRS feed

  • Question

  • Hi,

    I have created WCF restful service with post and get invoke method which has request/response format as JSON and I used a object(a user class object) as a parameter for mobi app. But the get method worked for me, unfortunately the POST method not worked. I received a error while calling the POST by passing JSON as param. Below is the error I received it.

    The server encountered an error processing the request. Please see the service help page for constructing valid requests to the service. The exception message is '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.'. See server logs for more details. The exception stack trace is:

    at System.ServiceModel.Dispatcher.DemultiplexingDispatchMessageFormatter.DeserializeRequest(Message message, Object[] parameters) at System.ServiceModel.Dispatcher.UriTemplateDispatchFormatter.DeserializeRequest(Message message, Object[] parameters) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc& rpc) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet). The surprising thing, it is working locally in my desktop, but after hosting the service in the windows server 2008 /iis7.5 it is displaying error when call the post method, but get method is working fine. I have researched most of the sites, but it never worked for me. Please help me in this.

    Friday, March 21, 2014 1:19 PM


  • Hi,

    A bad request error means that the data you are sending in the request is not in proper format.

    So please make sure you set the content type of the request to application/json.

    Also, set the WebMessageBodyStyle to wrappedRequest as below for the WCF service to expect a wrapped JSON string. by default it expects a plain String.

    [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]

    Then please try to use the fiddler to see what is the resquest and response.

    #Fiddler: .

    Best Regards,
    Amy Peng

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, March 24, 2014 6:24 AM