c# - Passing Model to Web API results in null value -


when try pass value web api using windows forms client this:

sessionmodel s = new sessionmodel() {     sessionid = "123456" }; using (var client = new httpclient()) { client.baseaddress = new uri("http://localhost:49584/"); client.defaultrequestheaders.accept.clear(); client.defaultrequestheaders.accept.add(new mediatypewithqualityheadervalue("application/json")); client.defaultrequestheaders.authorization = new authenticationheadervalue("bearer", txttoken.text.trim());  try {     httpresponsemessage response = await client.postasjsonasync("api/account/depositaccounts", s);     response.ensuresuccessstatuscode();    // throw if not success code.      if (response.issuccessstatuscode)     {         messagebox.show("results", "success!", messageboxbuttons.ok, messageboxicon.information);     } } catch (httprequestexception ex) {     messagebox.show(ex.message); } } 

and api controller code this:

 [httppost]  [authorize]  [route("depositaccounts", name = "depositaccounts")]  public httpresponsemessage getdepositaccounts(models.authenticationbindingmodel model)  {                  var sessionid = model.sessionid;  } 

when model comes in sessionid property null. confirmed not null on client side.

when use fiddler create json request on other hand works. missing on client side?

thanks.

** edit: changed property 'sessionid' 'sessionid' on client side. same issue though.

change api signiture getdepositaccounts(dynamic model) or use same class on both client , server side.


Comments

Popular posts from this blog

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

android - How to create dynamically Fragment pager adapter -

html - Outlook 2010 Anchor (url/address/link) -