MGOwen
MGOwen

Reputation: 7339

"ASP.NET Ajax client-side framework failed to load" with WCF - tried everything, still getting it

I now get the "ASP.NET Ajax client-side framework failed to load." javascript error in my asp.net 4 web site as soon as I run it (open the login page).

It used to only happen after I hit Ctrl-F5 (refresh page and all images/stylesheets/scripts) in browser while debugging.

My app uses asp.net 4 (originally written on 1.1 or 2), WCF, JsTree, some Telerik controls and MS AJAX extensions/toolkit.

In several days of googling, I found a large number of solutions given by people with the same problem (including ones here on SO and Telerik's help forums):

I tried the following, none worked for me:

Any other solutions to this problem?

I can post web.config or code if needed.

Update 1: More info
I looked at what was happening using firebug's "net" tab. GET requests for ScriptResource.axd and Webresource.axd are all failing with 404. Does this shed any further light on the issue?

Update 2: Partial solution? I used source control history to revert web.config back to before I added a WCF service to the website. The web.config that finally worked was just before I added this:

<system.serviceModel>
    <behaviors>
        <endpointBehaviors>
            <behavior name="FoldersAspNetAjaxBehavior">
                <webHttp/>
            </behavior>
        </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <services>
        <service name="Folders">
            <endpoint address="" behaviorConfiguration="FoldersAspNetAjaxBehavior" binding="webHttpBinding" contract="Folders" />
        </service>
    </services>
</system.serviceModel> 

...and removed the associated routing line from my global.asax:

routes.Add(new System.ServiceModel.Activation.ServiceRoute("", new System.ServiceModel.Activation.WebServiceHostFactory(), typeof(Folders)));

So one or both of those were the culprit. Can anyone suggest how a WCF service or it's routing could have caused this MS Ajax error?

This is my first ever WCF service. I barely understand what the above code is doing, but I'm suspecting a routing issue is at the heart of the problem somewhere...

Alternately - can anyone suggest an alternative to WCF? I can live without it if I can get my JSON data delivered to jquery another way. HttpHandler maybe, or WebService, or webform that spits out JSON as a response.write or something?

Update 2: Routing
Looks like the routing stuff in global.asax needed for the WCF service is the problem (see above). Commenting out that one line seems to fix the problem. Going to try changing the route path...

Solved: I solved it myself, see my accepted answer, but surely couldn't have done it so quickly without suggestions along the right track by some very insightful answers, thank you all.

Upvotes: 0

Views: 2044

Answers (7)

mahesh
mahesh

Reputation: 1

I got the problem. It was due to routing from the global.asax file all the scripts were redirecting to some other page and so it was difficult to find ajax script files for the page.

Upvotes: 0

MGOwen
MGOwen

Reputation: 7339

In my case, what actually fixed it was changing how I called the WCF service.

From tutorials I read on WCF, I missed the fact that I didn't need routing in the Global.asax to call the web service, and I could just call it like:

http://localhost/myWebApp/WcfService.svc/MethodName?param=value

(I had been relying on the routing in global.asax to let me call it like this: http://localhost/myWebApp/MethodName?param=value . I got rid of the routing and used the above way instead, and the problem disappeared)

Thanks all for insightful answers.

Upvotes: 0

Shiraz Bhaiji
Shiraz Bhaiji

Reputation: 65491

I think that the problem is related to the change in .net framework version.

The error is that it was unable to load the client side library. There are also some 404 errors which indicate that the problem was that the files were not retrieved from the server.

So all the ducks need to be in a row:

  • correct version of asp_net is registered
  • settings in web.config use correct version of framework
  • application pool is configured to use correct version of framework

Upvotes: 1

Steve Cooper
Steve Cooper

Reputation: 21500

It could be that the two handlers have been hijacked by WCF. You might try adding the handlers back in manually. If you merge in

<httpHandlers>
  <add path="WebResource.axd" verb="GET" type="System.Web.Handlers.AssemblyResourceLoader" validate="true"/>
</httpHandlers>

to your web config, does the WebResource.axd still return 404?

Upvotes: 1

Steve Cooper
Steve Cooper

Reputation: 21500

You can almost certainly do without WCF. Add a simple web service and add a method for each async call you want to make for JSON or XML. The two attributes you'll need to know about are WebMethod and scriptservice.

a walkthough on using them with jQuery can be found here

Upvotes: 1

Raj
Raj

Reputation: 6830

not sure about the ajax error(s), however you really dont need to have wcf if you are dealing with simple xml / json web services... i have replaced most of our wcf based services with restful xml / json webservices... most of these services are actually a simple aspx file where i am outputting my results in xml / json

.net framework comes with inbuilt xml / json readers and writers which you can use to convert your data structures (if any) to xml / json

an example: you can use the XmlTextWriter class to straight away write to the Response.OutputStream. eg:

XmlTextWriter xtw = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
xtw.WriteStartDocument();

Upvotes: 1

BarsMonster
BarsMonster

Reputation: 6583

Install browser extension which can log requests to the server. For example, FireBug for firefox. Then you need to check all requests browser made to your server and see if there are any errors or too-short responses.

Upvotes: 1

Related Questions