c# - Calling Web Method in Web Service -


basically trying consume web service methods in javascript class in asp.net. here methods in web service:

[webmethod]     public dataset getfirestation()     {         sqlconnection sqlconnection1 = new sqlconnection(configurationmanager.connectionstrings["dbconnectionstring"].connectionstring);         string select = "select * dbo.firestation ";         sqlconnection1.open();         // create adapter         sqldataadapter da = new sqldataadapter(select, sqlconnection1);         // create new dataset         dataset ds = new dataset();         // fill dataset contents of stock table         da.fill(ds, "firestation");         sqlconnection1.close();         // return ds dataset         return (ds);     } 

then here html code call function in javascript class:

 case "accident":             if (type == 'accident') {                 symbol = new esri.symbol.picturemarkersymbol('img/accident.gif', 25, 20);                 htmlstr = htmlstr + "<input type='button' id='btnhospoint' class='infotempbutton infotemporange' title='to hospital' value='' onclick='getsafetycoordxy(" + $(this).find("actualx").text() + ", " + $(this).find("actualy").text() + ", " + '\"' + type + '\"' + ");connectnearestroute(" + $(this).find("actualx").text() + ", " + $(this).find("actualy").text() + ");' />"                                     + "<input type='button' id='btnclinicpoint' class='infotempbutton infotemporange' title='to clinic' value='clinic' onclick='connectnearestclinic(" + $(this).find("actualx").text() + ", " + $(this).find("actualy").text() + ");' />"                                     + "<input type='button' id='btnfirepoint' class='infotempbutton infotemporange' title='nearest fire station' value='fs' onclick='connectnearsetfirestation(" + $(this).find("actualx").text() + ", " + $(this).find("actualy").text() + ");' />"                                     + "<input type='button' id='btnpolicepoint' class='infotempbutton infotemporange' title='nearest police station' value='police' onclick='connectnearsetpolice(" + $(this).find("actualx").text() + ", " + $(this).find("actualy").text() + ");' />";                 var point = new esri.geometry.point({ "x": $(this).find("actualx").text(), "y": $(this).find("actualy").text(), "spatialreference": { "wkid": 3414 } });                 var graphic = new esri.graphic(point, symbol);                 map.graphics.add(graphic);                  var infotemplate = new esri.infotemplate();                 infotemplate.settitle("<img src='img/accident.gif' style='width:25px; height:25px;'/>&nbsp;&nbsp; " + type);                 infotemplate.setcontent("information: " + incidentmessage + "</br>" + "</br>" + htmlstr);                  graphic.setsymbol(symbol);                 graphic.setinfotemplate(infotemplate);                 incidentlocation.push(graphic);                 htmlstr = "";             }             break; 

and here function in javascript class retrieve data database pass thru web service method:

edit

function connectnearsetfirestation(x, y) {      map.infowindow.hide();     //map.infowindow.resize(350, 120);      var fire = [];     var firestationpointgraphic = [];      $.ajax({         'type'          : 'get',         'url'           : 'http://localhost/sgdataservice.asmx' + 'getfirestation',     'success'       : function(results){     $.each(getfirestation(), function () {         var name = $(this).find("id").text();          firestation = $(this).find("name").text();         address = $(this).find("address").text();         postal = $(this).find("postalcode").text();         coordx = $(this).find("x").text();         coordy = $(this).find("y").text();          // compute distance         var incidentpoint = new esri.geometry.point({ "x": x, "y": y, "spatialreference": { "wkid": 3414 } });         var firestationpoint = new esri.geometry.point({ "x": coordx, "y": coordy, "spatialreference": { "wkid": 3414 } });         var distance = esri.geometry.getlength(incidentpoint, firestationpoint);          fire.push(distance);          var point = new esri.geometry.point({ "x": coordx, "y": coordy, "spatialreference": { "wkid": 3414 } });         var symbol = new esri.symbol.picturemarkersymbol('/safety_at_sg/images/features/firestation.gif', 25, 25);         var pointgraphic = new esri.graphic(point, symbol);          var infotemplate = new esri.infotemplate();          infotemplate.settitle("<img src='/safety_at_sg/images/features/policestation.png' style='width:25px; height:25px;'/>&nbsp;&nbsp; " + firestation);         infotemplate.setcontent("<b>firestation: </b>" + firestation + "<br/>"                 + "<b>address: </b>" + address + "<br/>"                 + "<b>postalcode: </b>" + postal + "<br/>"                 );         pointgraphic.setsymbol(symbol);         pointgraphic.setinfotemplate(infotemplate);          //store policestation array         firestationpointgraphic.push(pointgraphic);          //onemap.map.graphics.add(pointgraphic)     }     );     }     });      var mindist = math.min.apply(null, fire); //get smallest distance      (var = 0; < fire.length; i++) {         if (mindist == fire[i]) {             var myx = firestationpointgraphic[i].geometry.x;             var myy = firestationpointgraphic[i].geometry.y;              onemap.map.graphics.add(firestationpointgraphic[i]);             routeu(x + ',' + y + ";" + myx + ',' + myy);             break;         }     } } 

however, when try call getfirestation() in conenctnearestfirestation(), told me error message getfirestation not defined. wonder why so. need add reference web service if javascript class calling methods inside?

thanks in advance.

i think code should end this

function connectnearsetfirestation (x, y){      var fire = [];     var firestationpointgraphic = [];      var setroute = function (){         var mindist = math.min.apply(null, fire); //get smallest distance          (var = 0; < fire.length; i++) {             if (mindist == fire[i]) {                 var myx = firestationpointgraphic[i].geometry.x;                 var myy = firestationpointgraphic[i].geometry.y;                  onemap.map.graphics.add(firestationpointgraphic[i]);                 routeu(x + ',' + y + ";" + myx + ',' + myy);                 break;             }         }     }      var processfirestations = function (allfirestations){         $.each(allfirestations, function (){             var name = $(this).find("id").text();              firestation = $(this).find("name").text();             address = $(this).find("address").text();             postal = $(this).find("postalcode").text();             coordx = $(this).find("x").text();             coordy = $(this).find("y").text();              // compute distance             var incidentpoint = new esri.geometry.point({ "x": x, "y": y, "spatialreference": { "wkid": 3414 } });             var firestationpoint = new esri.geometry.point({ "x": coordx, "y": coordy, "spatialreference": { "wkid": 3414 } });             var distance = esri.geometry.getlength(incidentpoint, firestationpoint);              fire.push(distance);              var point = new esri.geometry.point({ "x": coordx, "y": coordy, "spatialreference": { "wkid": 3414 } });             var symbol = new esri.symbol.picturemarkersymbol('/safety_at_sg/images/features/firestation.gif', 25, 25);             var pointgraphic = new esri.graphic(point, symbol);              var infotemplate = new esri.infotemplate();              infotemplate.settitle("<img src='/safety_at_sg/images/features/policestation.png' style='width:25px; height:25px;'/>&nbsp;&nbsp; " + firestation);             infotemplate.setcontent("<b>firestation: </b>" + firestation + "<br/>"                     + "<b>address: </b>" + address + "<br/>"                     + "<b>postalcode: </b>" + postal + "<br/>"                     );             pointgraphic.setsymbol(symbol);             pointgraphic.setinfotemplate(infotemplate);              //store policestation array             firestationpointgraphic.push(pointgraphic);              //onemap.map.graphics.add(pointgraphic)         });          // once $.each over, map route         setroute();     };      var getfirestations = function (){         $.ajax({             'type'          : 'get',             'url'           : 'http://localhost/sgdataservice.asmx' + 'getfirestation',             'success'       : processfirestations         });     };        map.infowindow.hide();     //map.infowindow.resize(350, 120);      getfirestations();      // start } 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -