How to solve Only Web services with a [ScriptService] attribute on the class definition can be called from script

just add Attribute Class [ScriptService]

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]

old question. i had same problem, just removed contenttype from ajax call and it worked.


I just had exactly this same error message: "Only Web services with a [ScriptService] attribute on the class definition can be called from script.", but it had a totally different cause and solution.

It was working on my development machine, but not in production.

In my web.config I had:

<system.web>
  <httpHandlers>
    <remove verb="*" path="*.asmx"></remove>
    <add verb="*" path="*.asmx" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35"></add>
  </httpHandlers>
</system.web>

Replaced the Add tag with a newer assembly version:

<add verb="*" path="*.asmx" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

And it worked! Aparently the older assembly (1.0.61025.0) did not reccognise the attribute that was compiled against the newer (3.5.0.0) one.

Hope I can save someone the hours I needed to get to the bottom of this one!