c# - Sending unescaped JSON data to WCF via POST -


i have restfull wcf service, working fine when send escaped json data through post method. arises error bad request when send unescaped json. can tell me solution. interface code using in wcf.

  [servicecontract]   public interface iservice1   {     [operationcontract]     [webinvoke(method = "post", uritemplate = "loginclouduser", responseformat = webmessageformat.json, requestformat = webmessageformat.json)]     dnnloginresponse loginclouduser(string args);      [operationcontract]     usercredential getdatausingdatacontract(usercredential composite);      // todo: add service operations here   } 

update: using json.net serialize json. have tried removing codes , return arguments string. still gets error if json not escaped.

public dnnloginresponse loginclouduser(string args)     {         try         {             jsonserializersettings jss = new jsonserializersettings();             jss.stringescapehandling = stringescapehandling.default;              dnnlogin du = jsonconvert.deserializeobject<dnnlogin>(args, jss);             bool validateresult = dnnlogin.validateuser(du);               dnnloginresponse dlogres = new dnnloginresponse();              dlogres.result  = validateresult;             dlogres.resulttype = "success";              dlogres.userid = du.username;              return dlogres; //jsonconvert.serializeobject(dlogres, formatting.none, jss);          }         catch         {              dnnloginresponse dlogres = new dnnloginresponse();              dlogres.result = false;             dlogres.resulttype = "internal error";             dlogres.userid = string.empty;              return dlogres;           }     } 

i have removed json.net , changed code this, working well.

 [servicecontract]  public interface iservice1  {     [operationcontract]     [webinvoke(method = "post", uritemplate = "loginclouduser", responseformat = webmessageformat.json, requestformat = webmessageformat.json)]     dnnloginresponse loginclouduser(dnnlogin args);      [operationcontract]     usercredential getdatausingdatacontract(usercredential composite);      // todo: add service operations here } 

and function code.

       public dnnloginresponse loginclouduser(dnnlogin args)       {         try         {              bool validateresult = dnnlogin.validateuser(args);               dnnloginresponse dlogres = new dnnloginresponse();             if (validateresult)             {                 dlogres.result = validateresult;                 dlogres.resulttype =  "success" ;                 dlogres.userid = args.username;             }             else             {                 dlogres.result = validateresult;                 dlogres.resulttype = "login error";                 dlogres.userid = string.empty;              }               return dlogres; //jsonconvert.serializeobject(dlogres, formatting.none, jss);          }         catch         {              dnnloginresponse dlogres = new dnnloginresponse();              dlogres.result = false;             dlogres.resulttype = "internal error";             dlogres.userid = string.empty;              return dlogres;           }     } 

Comments

Popular posts from this blog

C# random value from dictionary and tuple -

cgi - How do I interpret URLs without extension as files rather than missing directories in nginx? -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -