昨日、Web API の実装が機能しました。今日入ったら、投稿パラメーターがエンティティ オブジェクトに逆シリアル化されなくなりました
これが私のAPIコントローラーコードです:
public class DocBooksMDController : ApiController
{
private BoxEntities db = new BoxEntities();
// POST api/DocBooksMD/ack
[HttpPost]
[ActionName("Acknowledge")]
public HttpResponseMessage MarkMessageAcknowledged(DocBooksMDMessage messageIn)
{
if (ModelState.IsValid)
{
// retrieve docBooksMDMessage
var query = from messages in db.DocBooksMDMessages
where messages.MessageControlID == messageIn.MessageControlID
select messages;
DocBooksMDMessage messageOut = query.FirstOrDefault();
if (messageOut == null)
{
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, new ArgumentException("Invalid Message Control ID"));
}
// Set Acknowledgement and Feedback
messageOut.DateAcknowledged = DateTime.Now;
messageOut.DocBooksFeedback = messageIn.DocBooksFeedback;
db.SaveChanges();
// send response
return Request.CreateResponse(HttpStatusCode.OK, messageOut);
}
else
{
return Request.CreateResponse(HttpStatusCode.BadRequest);
}
}
// POST api/DocBooksMD/read
[HttpPost]
[ActionName("Read")]
public HttpResponseMessage MarkMessageRead(DocBooksMDMessage messageIn)
{
if (ModelState.IsValid)
{
// retrieve docBooksMDMessage
var query = from messages in db.DocBooksMDMessages
where messages.MessageControlID == messageIn.MessageControlID
select messages;
DocBooksMDMessage messageOut = query.FirstOrDefault();
if (messageOut == null)
{
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, new ArgumentException("Invalid Message Control ID"));
}
// Set Read and Feedback
if (messageIn.DateRead == null) messageIn.DateRead = DateTime.Now;
messageOut.DateRead = DateTime.Now;
messageOut.DocBooksFeedback = messageIn.DocBooksFeedback;
db.SaveChanges();
// send response
return Request.CreateResponse(HttpStatusCode.OK, messageOut);
}
else
{
return Request.CreateResponse(HttpStatusCode.BadRequest);
}
}
protected override void Dispose(bool disposing)
{
db.Dispose();
base.Dispose(disposing);
}
}
}
これが私のエンティティクラスです:
public partial class DocBooksMDMessage
{
public int ID { get; set; }
public int ExamSourceID { get; set; }
public string PatientLastName { get; set; }
public string PatientFirstName { get; set; }
public string PatientMRN { get; set; }
public string ExamAccession { get; set; }
public string ExamCode { get; set; }
public string ExamDescription { get; set; }
public string ReferringProviderCode { get; set; }
public string ReferringProviderNPI { get; set; }
public string ReferringProviderLastName { get; set; }
public string ReferringProviderFirstName { get; set; }
public string Message { get; set; }
public string MessageControlID { get; set; }
public System.DateTime DateSent { get; set; }
public Nullable<System.DateTime> DateAcknowledged { get; set; }
public Nullable<System.DateTime> DateRead { get; set; }
public string DocBooksFeedback { get; set; }
}
昨日は機能したが、今日は機能しない json リクエストは次のとおりです。
Content-Type: application/json
Host: tbd:8080
Content-Length: 127
{
"MessageControlID":"65991775",
"DateAcknowledged":"2013-07-09T16:09:13.1564342-05:00",
"DocBooksFeedback":"Test Feedback"
}
どのように進めていけばよいのか、本当に困っています。
これは、そのメソッドが期待されるリクエストボディを取得していることを示しています:
string body = Request.Content.ReadAsStringAsync().Result;