【问题标题】:WCF: Why do I keep getting a 400 Bad Request Error?WCF:为什么我不断收到 400 错误请求错误?
【发布时间】:2011-10-28 12:54:36
【问题描述】:

我正在尝试使用 POST 调用 WCF 服务方法并发送编码为 json 的数据,但无论如何我总是收到错误的请求错误。

这是我的方法签名:

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

这是我的MeasurementData 模型定义:

[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; }
}

这就是我从客户端调用它的方式:

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);
     }
});

我有什么遗漏吗?

【问题讨论】:

    标签: c# wcf json


    【解决方案1】:

    您可以查看下面的帖子。

    400 Bad Request HTTP Response using a WCF POST via JQuery

    有些人已经遇到过这样的错误,它变成了与参数传递有关的错误。

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-04
      • 1970-01-01
      • 2020-11-11
      • 1970-01-01
      • 1970-01-01
      • 2018-05-09
      • 2013-01-26
      • 2022-12-03
      相关资源
      最近更新 更多