Thursday, June 20, 2013

ASP.NET AJAX Javscript call - Web Service is undefined Error

I tried to implement this using a script manager and script enabledWS but constantly kept getting the error 'service is undefined'. Talk about infuriating.

I ripped my web.config apart trying to find the problem, hacked my code, moved scripts - alsorts! Searched high and low on the net but could not find the solution to the problem anywhere. I had a sample project that it worked fine in and everything was exactly the same (well almost).

Then i started looking at references. When doing this i spotted thenamespace in my project which lit a light bulb. The sample project was a Web Project and there is no namespace property like on the project. So i went back to my javascript and changed the following line as follows:

Webservicename.Webmethod(prams, callback);

to

Namespace.Webservicename.Webmethod(prams, callback);

Worked a treat!

Hopefully this will save someone a days worth of head scratching and wasted time like myself.

Ad Inside Post

Comments system

Disqus Shortname