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.
i added ajax enabled scriptmanager default.aspx design view , right clicked 'properties' view. added sevice name:
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 -
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
Post a Comment