c# - Send Android class to WCF webservice -


i trying use rest, send exposed webservice. 400 (bad request.)

how property send model across rest, correctly map model on other side. don't want do, have 100 parameters exposed individually in connection point.

    [operationcontract]     [webinvoke(         method = "post",         uritemplate = "savedata",         bodystyle = webmessagebodystyle.wrappedrequest,         responseformat = webmessageformat.json,         requestformat = webmessageformat.json)]     void savedata(datum data); 

but unable pass valid datum object.

     // build json string      jsonstringer vehicle;     try {         vehicle = new jsonstringer()              .object()                  .key("datum")                      .object()                          .key("id").value(5)                          .key("name").value("test")                          .key("no").value(54)                          .key("description").value("test")                      .endobject()                  .endobject();         httppost request = new httppost(address + "/savedata");      log.d("webinvoke", "connection : " + address + "/savedata");      request.setheader("accept", "application/json");      request.setheader("content-type", "application/json");          stringentity entity = new stringentity(vehicle.tostring());          log.d("stringentity", vehicle.tostring());          request.setentity(entity);           // send request wcf service          defaulthttpclient httpclient = new defaulthttpclient();          httpresponse response = httpclient.execute(request);           log.d("webinvoke", "saving : " +    response.getstatusline().getstatuscode());              // saving : 400 

datum class:

[datacontract] public partial class datum {     [datamember(name = "id")]     public int id { get; set; }        [datamember(name = "name")]     public string name { get; set; }      [datamember(name = "no")]     public nullable<int> no { get; set; }          [datamember(name = "description")]     public string description { get; set; } } 

it should be:

vehicle = new jsonstringer()              .object()                  .key("data")                      .object()                          .key("id").value(5)                          .key("name").value("test")                          .key("no").value(54)                          .key("description").value("test")                      .endobject()                  .endobject();  

source: wcf bodystyle wrappedrequest doesn't work incoming json param?


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -