0

I'm trying to invoke a WCF service method using POST and sending data encoded as json but no matter what I keep getting a bad request error.

This is my method signature:

[WebInvoke(Method = "POST", 
           RequestFormat = WebMessageFormat.Json, 
           BodyStyle = WebMessageBodyStyle.WrappedRequest)]
public int Publish(List<MeasurementData> data)

This is my MeasurementData model definition:

[DataContract]
public class MeasurementData
{
   [DataMember]
   public string ReadingDate;

   [DataMember]
   public int Unit { get; set; }

   [DataMember]
   public string ParameterAbbreviation { get; set; }

   [DataMember]
   public decimal Measurement { get; set; }
}

And this is how I'm calling it from the client:

var data = '[{"Measurement": 12678967.543233, "ParameterAbbreviation": "String content", "ReadingDate": "String content","Unit": 2147483647}]';

$.ajax({
    type: "POST",
    url: "/SiennaAddMeasurement/Publish",
    data: "{ 'data' : '" + data + "' }",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (msg) {
        alert(msg.d);
     }
});

Is there something I'm missing?

Ghyath Serhal
  • 7,466
  • 6
  • 44
  • 60
Raúl Roa
  • 12,061
  • 13
  • 49
  • 64

1 Answers1

0

you can check this below post.

400 Bad Request HTTP Response using a WCF POST via JQuery

some one has already faced such an error it turned to be an error related to the parameters pass.

hope it can help

Community
  • 1
  • 1
SShebly
  • 2,043
  • 1
  • 21
  • 29