vb.net - asmx won't return JSON -
i've rewritten old asmx service function still can't return json. returns xml, if use ajax() , set datatype , contenttype json. i'm trying use function jquery datatables. , know there tons of questions of them i've found c# , unable adapt them.
up-to-date pastebin of full asmx file: http://pastebin.com/swxkqgd4
new code
<webmethod()> _ <webget(responseformat:=webmessageformat.json)> _ public function rptpendingserverrequests() generic.list(of request) dim _conn sqlconnection = new sqlconnection(connectionstring) dim _dr sqldatareader dim sql string = string.empty sql += "<my query here>" try dim _cmd sqlcommand = new sqlcommand(sql, _conn) _conn.open() _dr = _cmd.executereader(commandbehavior.closeconnection) if _dr.hasrows dim s request dim c new generic.list(of request) while _dr.read s = new request s .requestid = _dr("request_id") .status = _dr("status") .requester = _dr("req_by_user_id") .assignee = _dr("user_id") .nextaction = _dr("description") end c.add(s) end while return c end if catch ex exception msgbox(ex.message) _conn.close() end try end function new class
<serializable()> _ public class request private _requestid integer public property requestid() integer return _requestid end set(byval value integer) _requestid = value end set end property private _requester string public property requester() string return _requester end set(byval value string) _requester = value end set end property private _requestdate date public property requestdate() date return _requestdate end set(byval value date) _requestdate = value end set end property private _status integer public property status() integer return _status end set(byval value integer) _status = value end set end property private _assignee string public property assignee() string return _assignee end set(byval value string) _assignee = value end set end property private _nextaction string public property nextaction() string return _nextaction end set(byval value string) _nextaction = value end set end property end class original code
<webmethod()> _ <webget(responseformat:=webmessageformat.json)> _ public function rptpendingserverrequestsold() dataset dim connection sqlconnection dim command sqlcommand dim adapter new sqldataadapter dim ds new dataset dim sql string sql = "" sql += "<my query here>" connection = new sqlconnection(connectionstring) try connection.open() command = new sqlcommand(sql, connection) adapter.selectcommand = command adapter.fill(ds) adapter.dispose() command.dispose() connection.close() return ds catch ex exception end try end function client
$('#report').datatable({ "bprocessing": true, "sajaxsource": 'reportdata.asmx/rptpendingserverrequests' });
since you're calling method js instead of
<webget(responseformat:=webmessageformat.json)> use
<scriptmethod(responseformat:=responseformat.json)> attribute. don't forget mark webservice class with
<scriptservice()> attribute.
Comments
Post a Comment