json - Call dynamic method in c# -
i have json request parameters
{ "exp": 0, "iat": 0, "method": "login", "apisecretkey": "y109m113e122", "username": "test@test.com", "password": "test", "isguestcustomerid": 1 }
and method in wcf rest api service(c#)
login(string apisecretkey, string username, string password, int isguestcustomerid)
how pass these request parameter login method?
note : have around 200 methods call in way different parameters like
register(string apisecretkey, string emailid, string password, string firstname, string lastname, string phonenumber, string gender, string dateofbirth, string companyname) , on different methods
thanks in advance.
using json.net,
var jobj = jobject.parse(json); object instance = .... ; //instance of class containing methods.. var mi = instance.gettype().getmethod(jobj["method"].tostring(), bindingflags.instance | bindingflags.public | bindingflags.nonpublic); var parameters = mi.getparameters() .select(p => convert.changetype(jobj[p.name].tostring(), p.parametertype)) .toarray(); object retval = mi.invoke(instance, parameters);
Comments
Post a Comment