c# - Azure Mobile Service .NET Backend HttpResponseMessage return null Content -
i had function in web api of mobile service declared
public httpresponsemessage post(loginrequest loginrequest) { easyparkcontext context = new easyparkcontext(); user user = context.users.singleordefault(a => a.username == loginrequest.username); if (user != null) { if (bcrypt.net.bcrypt.verify(loginrequest.password, user.password)) { claimsidentity claimsidentity = new claimsidentity(); claimsidentity.addclaim(new claim(claimtypes.primarysid, user.id)); claimsidentity.addclaim(new claim(claimtypes.nameidentifier, loginrequest.username)); loginresult loginresult = new easyparkloginprovider(handler).createloginresult(claimsidentity, services.settings.masterkey); return this.request.createresponse(httpstatuscode.ok, loginresult); } } return this.request.createresponse(httpstatuscode.unauthorized, "invalid username or password"); }
and function declared in client
public async task<bool> login(string username, string password) { loginrequest loginrequest = new loginrequest() { username = username, password = password }; try { httpresponsemessage loginresult = await _service.invokeapiasync<loginrequest, httpresponsemessage>("easyparklogin", loginrequest); jobject json = jobject.parse(loginresult.content.tostring()); _service.currentuser = new mobileserviceuser(json["user"]["userid"].tostring().replace("easypark:", "")) { mobileserviceauthenticationtoken = json["authenticationtoken"].tostring() }; return true; } catch (exception e) { return false; } }
it works @ mobile service page, returning null during client code, sorry can't attached image due reputation...
public async task<bool> login(string username, string password) { loginrequest loginrequest = new loginrequest() { username = username, password = password }; try { var loginresult = await _service.invokeapiasync("easyparklogin", jtoken.fromobject(loginrequest)); jobject json = jobject.parse(loginresult.tostring()); _service.currentuser = new mobileserviceuser(json["user"]["userid"].tostring().replace("easypark:", "")) { mobileserviceauthenticationtoken = json["authenticationtoken"].tostring() }; return true; } catch (exception e) { return false; } }
by changing code:
httpresponsemessage loginresult = await _service.invokeapiasync<loginrequest, httpresponsemessage>("easyparklogin", loginrequest); jobject json = jobject.parse(loginresult.content.tostring());
to
var loginresult = await _service.invokeapiasync("easyparklogin", jtoken.fromobject(loginrequest)); jobject json = jobject.parse(loginresult.tostring());
Comments
Post a Comment