c# - Implementing an AJAX enabled WCF Service - call from JQuery not responding -


i'm going through example posted on msdn can't work. have asp web form project in vs2015 ajax enabled wcf service. i've hit cntrl-f5 worked ok. tried entering uri in browser , got appropriate response. enter image description here

i added ajax enabled scriptmanager default.aspx design view , right clicked 'properties' view. added sevice name:

enter image description here

here's service itself:

namespace candidatetest.service{ [servicecontract(namespace = "candidatetest.service")] [aspnetcompatibilityrequirements(requirementsmode = aspnetcompatibilityrequirementsmode.allowed)] public class ethorservice {     public string button;     [webget()]     [operationcontract]     public void getupdate()     {         _default def = new _default();         console.writeline("wcf service working");         def.renderdata(button);     } } 

}

here's jquery script i'm trying call service from:

$(function () { //while ($('#ethorbutton').text != "stop") { if ($('#ethorbutton').click) {     alert("apc2"); $.ajax({      url: 'http://localhost:49620/service/ethorservice.svc/getupdate',     method: 'post',     datatype: 'json',     success: function(){         alert("success");     },     error: function (err) {         alert(err);     }  }) //delay(1000); alert("here"); }    }); 

the changes creating service made web.config default haven't changed:

<system.servicemodel> <services>   <service name="candidatetest.service.ethorservice">     <endpoint address="" behaviorconfiguration="candidatetest.service.ethorserviceaspnetajaxbehavior"       binding="webhttpbinding" contract="candidatetest.service.ethorservice" />   </service> </services> <behaviors>   <endpointbehaviors>     <behavior name="candidatetest.service.ethorserviceaspnetajaxbehavior">       <enablewebscript />     </behavior>   </endpointbehaviors>   <servicebehaviors>     <behavior name="">       <servicemetadata httpgetenabled="true" httpsgetenabled="true" />       <servicedebug includeexceptiondetailinfaults="false" />     </behavior>   </servicebehaviors> </behaviors> <servicehostingenvironment aspnetcompatibilityenabled="true"   multiplesitebindingsenabled="true" /> 

end point empty might issue?

so first attempt @ creating ajax enabled service in wcf , script doesn't call service. alerts added see if script consuming service @ , appears not be.

i've followed example on enter link description here vs2012 i'm hoping that's not issue. need script call service?

edit

on inspecting script in chrome's dev tools, 2 errors - enter image description here

so script can't find web service although appears correct url.

edit fixed script reference error service call still returns 404

it looks page doesn't have reference jquery javascript file.

your ajax call using post verb, service set webget() attribute, meaning need modify ajax call use verb:

$.ajax({      url: 'http://localhost:49620/service/ethorservice.svc/getupdate',     method: 'get',     datatype: 'json',     success: function(){         alert("success");     },     error: function (err) {         alert(err);     }  }) 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -