I cannot call webmethod from jquery. I think its about web.config file. How can i set web.config file for web services and webmethod?
Asked
Active
Viewed 1,185 times
0
-
Doing just a spot check on his answers, I didn't see anything worth marking as an answer. Might just be me, but perhaps he could provide what he did in some of those questions. – Yuriy Faktorovich Nov 08 '10 at 21:56
-
Ok guys, come down please :) I did check my questions and mark some of answers as an "answer". – pegasus Nov 08 '10 at 22:02
1 Answers
0
Do you have this code?
$.ajax({
url: "Services/MyService.svc/Service",
type: "GET",
context: document.body,
contentType: 'application/json; charset=utf-8',
datatype: 'json',
success: function (data) {
// do something
}
});
note that contentType part is critical.
If you do, check Firebug for exact error that gets thrown in the "Net" tab. Normally, people have different problems depending on service type - ASP.NET asmx vs. WCF svc. For asmx configuration, refer to How to let an ASMX file output JSON . For wcf, you need to set up web.config to allow web scripting, like so:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="AspNetAjaxBehavior">
<enableWebScript/>
</behavior>
</endpointBehaviors>
</behaviors>
and then later configure the service to use that behavior:
<services>
<service name="MyProject.Services.MyService">
<endpoint address="/Services/MyService.svc" behaviorConfiguration="AspNetAjaxBehavior" binding="webHttpBinding" contract="MyProject.Services.MyService"/>
</service>
</services>
</system.serviceModel>
-
That's right! But i want to visual studio write these code automatically. – pegasus Nov 08 '10 at 22:49
-
1not possible - visual studio doesn't have any automation with the help of jQuery. you can however use ASP.NET AJAX with servicereference - then it will be generated automatically, with method names, parameters etc. See http://msdn.microsoft.com/en-us/library/bb514961.aspx#sectionToggle1 – Artemiy Nov 09 '10 at 13:55