【问题标题】:C# accepting Image as HttpPostedFile in Restful APIC# 在 Restful API 中接受图像作为 HttpPostedFile
【发布时间】:2012-05-11 07:08:32
【问题描述】:

我正在用 C# 构建一个 rest api - 我正在设置一些 POST - 这是界面:

    [SecurityTokenValidator("Registered Users")]
    [OperationContract]
    [WebInvoke(ResponseFormat = WebMessageFormat.Xml, RequestFormat = WebMessageFormat.Xml, UriTemplate = "camps/{campid}/markings/{token}", Method = "POST")]
    MarkingDto InsertMarking(string campid, string token, MarkingDto markingDto);

这是我的 MarkingDto

[DataContract(Namespace = "FreeBeer")]
public class MarkingDto
{
    [DataMember] public int Id;
    [DataMember] public decimal Latitude;
    [DataMember] public decimal Longitude;
    [DataMember] public string MarkingType;
    [DataMember] public DateTime DateTime;
}

在 Fiddler 中构建测试 POST 时 - 我注意到我的 RequestBody 不是按字母顺序排列的 - 有些项目出现空值或零。例如 - 如果请求正文是这样 - 经度在纬度之前出现 - 纬度将为零 (0)。

<MarkingDto xmlns="BigGameLogic">
<Longitude>456</Longitude>
<Latitude>123</Latitude>
<MarkingType>Scrape</MarkingType>
</MarkingDto>

但如果按字母顺序排列 - 一切都在那里。这只是提琴手的事情吗?或者这是我需要解决的问题,因为我缺少简单的解决方案;)

【问题讨论】:

    标签: c# asp.net rest post fiddler


    【解决方案1】:

    WCF 中要求除非您在 DataMember 上指定顺序,否则成员属性将按字母顺序发送。

    请看这个问题的答案

    Not all parameters in WCF data contract make it through the web service call

    更多信息可以在这里找到

    msdn.microsoft.com/en-us/library/ms729813.aspx

    谢谢

    【讨论】:

    • 感谢您澄清这一点 - 就像@Robert Harvey 的另一个 SO 问题一样 - 让程序员想要扼杀某人的东西
    猜你喜欢
    • 2017-02-24
    • 1970-01-01
    • 1970-01-01
    • 2019-05-31
    • 2013-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-07
    相关资源
    最近更新 更多