Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • almir 11 posts 26 karma points
    Aug 04, 2009 @ 11:01
    almir
    0

    Jquery ajax calls

    Hi

    The following jquery code makes a call to the webservice:

     $.ajax({        type: "POST",
                        url: "/Orders.asmx/InsertOrder",
                        data: "{cartID:" + cartID + "}",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function(msg) {
                            $('#OrderID').val(msg.d);
                                    },
                        error: function(xhr) {
                            alert(xhr.status);
                        }
                    });

    It is supposed to send shopping cart id and return order id. It works in non umbraco site, when imported into umbraco as a part of an asp.net page it fails with xhr.status 500 which will translate into internal server error.

    Both the page making call and oredrs.asmx are added to umbraco reserved urls. The umbraco version 4.021 is installed on the site.

    Any help with this problem will be greatly appreciated.

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Aug 04, 2009 @ 11:04
    Peter Dijksterhuis
    2

    Try adding these lines in your web.config (in system.web-part):

        <webServices>
          <protocols>
            <add name="HttpGet"/>
            <add name="HttpPost"/>
          </protocols>
        </webServices>
    HTH,
    Peter

  • almir 11 posts 26 karma points
    Aug 04, 2009 @ 11:32
    almir
    0

    Bedankt, geen geluk.

    Thanx Peter it did not work.

    Just to clear, I tested webservice localy and it works ok. I also tried setting full path to orders.asmx (hardcoded and via js), it did not work.

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Aug 04, 2009 @ 12:08
    Peter Dijksterhuis
    0

    Hm ok, not exactly what I expected.

    Are you able to test the webservice remotely? Or does it only work locally?

  • almir 11 posts 26 karma points
    Aug 04, 2009 @ 12:35
    almir
    0

    Yep works remotely, I made a test project with a webreference to orders.asmx and everything works ok.

    Must be something that prevents a script call.

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Aug 04, 2009 @ 12:45
    Peter Dijksterhuis
    0

    Perhaphs the data that gets posted to the webservice is not correct then so it throws a 500?

  • almir 11 posts 26 karma points
    Aug 04, 2009 @ 13:15
    almir
    0

    Debugged js data, also use a simple alert box to check the value, aalso checked database values, the value passed for cartID seems to be correct.

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Aug 04, 2009 @ 13:20
    Peter Dijksterhuis
    0

    If it throws a 500-error, maybe you can get additional info from the event-log or from the umbracoLog-table. Other than that, I'm pretty much running out of options!

  • almir 11 posts 26 karma points
    Aug 04, 2009 @ 13:43
    almir
    0

    Het is zo lastig.

    Should have checked event log long time ago. It reads as follows:
      Exception message: Only Web services with a [ScriptService] attribute on the class definition can be called from script.

    Well I do have it on my class:

    ...
    Imports System.Web.Script.Services

    ' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
    ' <System.Web.Script.Services.ScriptService()> _
    <System.Web.Services.WebService(Namespace:="http://tempuri.com/")> _
    <System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
    <ToolboxItem(False)> _
    <ScriptService()> _
    Public Class Orders1
        Inherits System.Web.Services.WebService

    ...

     

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Aug 04, 2009 @ 13:55
    Peter Dijksterhuis
    2

    Hm, now you mention it, I did have that same issue. I'm using C# though, but this is what my class looks like:

            [WebMethod]
            [ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
            public string SaveWiki(string source, string parent)
            {
    Without the WebMethod, it didn't work either.

  • almir 11 posts 26 karma points
    Aug 04, 2009 @ 14:22
    almir
    0

    The company policy to use VB, I use both no probs I did have WebMethod attribute, not the ScriptMethod though, it is now in place to no avail.

    I just wonder the site is compiled on 3.5 platform, I am using Linq, and braco site web.config is tuned for asp.net 2.0, would that be an issue, maybe referencing different assembly or similar?

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Aug 04, 2009 @ 14:33
    Peter Dijksterhuis
    0

    I think I spotted the point where it goes wrong.

    You set the ScriptService on the Class. You also need to set the ScriptService on your procedure (InsertOrder) to make it work.

  • almir 11 posts 26 karma points
    Aug 04, 2009 @ 15:07
    almir
    0

    <System.Web.Script.Services.ScriptService()> is a class attribute, cann'ot be applied to the method.

    I did search on the error message and part of the stack in Google:

    Only Web services with a [ScriptService] attribute on the class definition can be called from script.System.Web.Script.Services.WebServiceData.GetWebServiceData(HttpContext context, String virtualPath, Boolean failIfNoData, Boolean pageMethods)

    I would say according to some of the results that the issue may be in web.config settings, but I can't be sure as yet.

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Aug 04, 2009 @ 15:35
    Peter Dijksterhuis
    0

    Let me explain what I have in my code:

    On the class, I have this: 

    [System.Web.Script.Services.ScriptService]
    public class blahblah

    On the method, I have this: 

    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
    public string blahstring

    From the top of my head, only the attribute on the class is not enough. Now I'm not sure which one solved my problem, adding the webmethod or the scriptmethod.

    Only thing I added to my web.config was the piece I posted earlier. Other than that, I made no changes. I think you should look in the code. Mainly because you get a 500-error (that makes me think the page get called, but somehow throws an error)

     

  • almir 11 posts 26 karma points
    Aug 04, 2009 @ 15:53
    almir
    1

    Well I have all that as well, I found out what that was, I had to change all the settings in web.config in connection with ajax to reference ASP.NET 3.5 assemblies.

    That 500 error is a red herring.

    Anyway without your help I may not have solved it by now, I tahnk you for that.

    Bedankt. Grooten an iederen in Flevoland from Engeland, daar ben ik nooit geweest.

     

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Aug 04, 2009 @ 15:58
    Peter Dijksterhuis
    0

    Ah, didn't think that it would matter, but apparantly it does. Good to know! (I wish I advised you to use the 3.5-configfile to check if it would matter, but I really thought it wouldn't)

    Graag gedaan ;)

  • marthin 87 posts 106 karma points
    Feb 12, 2010 @ 13:15
    marthin
    0

    Hi, could someone please post the solution, the web.config that is. Im having the same problem when using jQuerey. Thx!

  • Daniel Lindstrom 454 posts 271 karma points
    Feb 13, 2010 @ 01:39
    Daniel Lindstrom
    0

    The web config for 3.5 i available from codeplex: http://umbraco.codeplex.com/releases/view/33743

Please Sign in or register to post replies

Write your reply to:

Draft