asp.net web api - Web Api Get FromUri - ArrayList Issue -
i new in web api , trying converting web service web api. encountered issue while running web api. please in issue.
i have declared 2 arraylist (parametername & parametervalue) in class model , optional have value in both parameters.
public class pnawcfdata { public pnawcfdata() { server = ""; database = ""; loginid = ""; password = ""; cmdtimeout = 30; success = false; } public string server { get; set; } public string database { get; set; } //...... public arraylist parametername { get; set; } public arraylist parametervalue { get; set; } //......
when running it... http://localhost:53386/api/webapi?server=pnante813&database=ff_andon&storedprocname=udpdev_getprojectbyplant¶metername=plant¶metervalue=plant1
if did not put value parametername & parametervalue, able result.
if put value (plant & plant1) parametername & parametervalue, still success somehow returned nothing. supposed return value.
controller code:
namespace pnawebapi.controllers { public class webapicontroller : apicontroller { public pnawcfdata getexecprocedurewithoutput([fromuri] pnawcfdata ppnawcfdata) { string lsconnstr; if (checkconndata(ppnawcfdata.server, ppnawcfdata.database, ppnawcfdata.loginid, ppnawcfdata.password) == false) { ppnawcfdata.success = false; ppnawcfdata.errmsg = "database connection info not provided!"; } else { lsconnstr = getconnstr(ppnawcfdata.server, ppnawcfdata.database, ppnawcfdata.loginid, ppnawcfdata.password); try { if (ppnawcfdata.storedprocname == "") { ppnawcfdata.success = false; ppnawcfdata.errmsg = "invalid stored procedure!"; } else { using (sqlconnection loconn = new sqlconnection(lsconnstr)) { using (sqlcommand locmd = new sqlcommand(ppnawcfdata.storedprocname, loconn)) { locmd.commandtype = system.data.commandtype.storedprocedure; locmd.commandtimeout = ppnawcfdata.cmdtimeout; if (ppnawcfdata.parametername != null && ppnawcfdata.parametervalue != null) { (int = 0; < ppnawcfdata.parametername.count; ++i) { locmd.parameters.addwithvalue(ppnawcfdata.parametername[i].tostring(), ppnawcfdata.parametervalue[i]); } } if (loconn.state =............. .................... catch (exception ex) { ppnawcfdata.success = false; ppnawcfdata.errmsg = ex.message; } } return ppnawcfdata; }
most there's problem parameter binding in getexecprocedurewithoutput method class uses arraylist can't populated fromuri attribute.
instead of using arraylist try , use "simpler" parameter type string[]
or list<string>
.
Comments
Post a Comment