Note that there are some explanatory texts on larger screens.

plurals
  1. POJson Wrapped object Post always null
    primarykey
    data
    text
    <p>[Edited message with more info and fiddler requests]</p> <p>I am trying to call a Post webmethod server side defined like this:</p> <pre><code>[OperationContract] [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest, UriTemplate = "SaveMessage")] void SaveMessage(Message msg); </code></pre> <p>the Message class is defined as such:</p> <pre><code>public class Message { public int Id { get; set; } public int FromId { get; set; } public int ToId { get; set; } public string Subject { get; set; } public string From { get; set; } public string To { get; set; } public DateTime DateTime { get; set; } public string Msg { get; set;} public bool IsRead { get; set; } } </code></pre> <p>with the following Request (wrapped):</p> <pre><code>POST http://192.168.2.40:9001/AFMServer/SaveMessage HTTP/1.1 Content-Type: application/json Host: 192.168.2.40:9001 Content-Length: 204 Expect: 100-continue Connection: Keep-Alive { "msg": { "Id": 0, "FromId": 0, "ToId": 0, "Subject": null, "From": "", "To": null, "DateTime": "0001-01-01T00:00:00", "Msg": null, "IsRead": false } } </code></pre> <p>The request is <strong>NOT</strong> received server side although it's wrapped as specified by the WebInvoke property.</p> <p>The following (bare) request however:</p> <pre><code>POST http://192.168.2.40:9001/AFMServer/SaveMessage HTTP/1.1 Content-Type: application/json Host: 192.168.2.40:9001 Content-Length: 169 Expect: 100-continue Connection: Keep-Alive { "Id": 0, "FromId": 0, "ToId": 0, "Subject": null, "From": "", "To": null, "DateTime": "0001-01-01T00:00:00", "Msg": null, "IsRead": false } </code></pre> <p>Is received but msg is null (which makes sense, I guess, since the json is not wrapped). Can somebody help me find out why the first request is unsuccessful?</p> <p>Thanks!</p> <p>NB: I am using <strong>Json.Net</strong></p> <p>[EDIT 2] <strong>If I remove the DateTime field from the Message class, it WORKS! Still trying to figure out why</strong></p> <p>[EDIT 3] Workaround is written below as an answer - HTH! :-)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload