c# - How can I have multiple handlers in same ProcessRequest method? -
i calling rest service ajax, have following example call
myipaddress/restwebservice/employee?id=1",
the c# service code shown below. handler above "employee", wish add more handlers , wondering can same processrequest method, parse out handler , direct request paramaters required,
so have call like
myipaddress/restwebservice/company?id=1",
many thanks
void ihttphandler.processrequest(httpcontext context) { try { string url = convert.tostring(context.request.url); connstring = @""; dal = new dal.dal(connstring); errhandler = new errorhandler.errorhandler(); //handling crud switch (context.request.httpmethod) { case "get": //perform read operation read(context); break; case "post": //perform create operation create(context); break; case "put": //perform update operation update(context); break; case "delete": //perform delete operation delete(context); break; default: break; } } catch (exception ex) { errhandler.errormessage = ex.message.tostring(); context.response.write(errhandler.errormessage); } } /// <param name="context"></param> private void read( httpcontext context) { try { int employeecode = convert.toint16(context.request["id"]); //http request type - get" //performing operation - read" //data sent via query string //post - data sent name value pair , resides in <form section> of browser emp = dal.getemployee(employeecode); if (emp==null) context.response.write(employeecode + "no employee found"); string serializedemployee = serialize(emp); context.response.contenttype = "text/xml"; //string serializedemployee = jsonserialize(emp); //context.response.contenttype = "text/json"; writeresponse(serializedemployee); } catch (exception ex) { writeresponse("error in read"); errhandler.errormessage = dal.getexception(); errhandler.errormessage = ex.message.tostring(); } }
i not sure implementaiton in c# in java rest frameworks can have varying value of path params, processed method. here rest convention it
myipaddress/restwebservice/{entity}?id=1 @ run time can cater both type of request myipaddress/restwebservice/employee?id=1 myipaddress/restwebservice/company?id=1
i hope c# framework should providing feature rest convention.
Comments
Post a Comment