Copied to clipboard

Flag this post as spam?

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


  • Brendan Rice 538 posts 1100 karma points
    Jun 25, 2010 @ 17:25
    Brendan Rice
    0

    JQuery Ajax Serverside Method Call

    I am trying to call the method below through a  jQuery Ajax call (see below).  I can hit the AjaxMethods.aspx page without any problems but for some reason I keep getting a 404 error when trying to hit the web method.

    Has anyone got any ideas? 

    Thanks in advance.

            [WebMethod()]
            public static string sayHello()
            {
                return "hello ";
            }

     

        $(document).ready(function() {
            $.ajax({
              type: "POST",
              url: "AjaxMethods.aspx/sayHello",
              contentType: "application/json; charset=utf-8",
              data: "{}",
              dataType: "json",
              success: AjaxSucceeded,
              error: AjaxFailed
            });
        });
  • Dan 1285 posts 3917 karma points c-trib
    Jun 25, 2010 @ 17:28
    Dan
    0

    Have you tried using an absolute URL in your jQuery script?

  • Brendan Rice 538 posts 1100 karma points
    Jun 25, 2010 @ 21:04
    Brendan Rice
    0

    Thanks for the reply Dan, here is what I have tried:

    • I have tried using relative & absolute URLs without any luck
    • I have tried to hit the method through the browser and it doesn't work i.e. Http://.../page.aspx/method
    • I have tried putting an ASPX page in the root of the virtual directory and placing the method in it again it didn't work
    The Umbraco solution is built against v2.0 of the .Net Framework, would this make any difference?

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Jun 27, 2010 @ 10:47
    Aaron Powell
    0

    I've never had page methods working with Umbraco, essentially I think the root problem with that it's coming in via a ASPX page.

    You're better off using Web Services (ASMX).

  • Julius Bartkus 51 posts 76 karma points
    Jul 17, 2010 @ 16:00
    Julius Bartkus
    0

     

    The problem I guess is stated in this topic http://forum.umbraco.org/yaf_postst5698_Problems-with-webservices-Umbraco-V4.aspx

    And the problem is the translation of the URL to the lowercase.

    It means that when you call AjaxMethods.aspx/sayHello it throws an exception that the method is case sensitive, because umbraco translates the URL to ajaxmethods.aspx/sayhello

    Please correct me if i am wrong.

    Does anyone found a solution for that issue?

  • Julius Bartkus 51 posts 76 karma points
    Jul 17, 2010 @ 19:25
    Julius Bartkus
    0

    I am running umbraco 4.5 on iis7 

    and get the following error when I call

    http://www.smspunkt.dk/webservices/SMSService.asmx/GetBalance

     

    System.ArgumentException: Invalid method name 'getbalance',  method names are case sensitive.   The method name 'GetBalance' with the same name but different casing was found.
    Parameter name: methodName
       at System.Web.Services.Protocols.HttpServerProtocol.Initialize()
       at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)

     

    Does anyone know how to fix it?

     

  • Sascha Wolter 615 posts 1101 karma points
    Jul 17, 2010 @ 20:34
    Sascha Wolter
    0

    Hi Julius,

    Try setting the MessageName field on the web method attribute which is all lowercase, like so:

    [WebMehod(MessageName = "mywebmethodname")]

    (http://msdn.microsoft.com/en-us/library/byxd99hx(VS.71).aspx#vbtskusingwebmethodattributemessagename)

    I'm afraid I've forgotten why this lower/uppercase issue occurs, but this should help.

    Sascha

  • Julius Bartkus 51 posts 76 karma points
    Jul 17, 2010 @ 23:02
    Julius Bartkus
    0

    Hey Sascha,

    thanks for the answer.

    Unfortunately the solution is not suitable, because then my customers need to change method name to the lower-case.

    Do you know if it is possible to solve it any other way?

    /Julius

  • Sascha Wolter 615 posts 1101 karma points
    Jul 18, 2010 @ 02:28
    Sascha Wolter
    0

    Hi Julius,

    apparently this is just a bit of a hack with executing the web service directly from within the browser, aka if you browse to www.smspunkt.dk/.../GetBalance. I have added the lowercase alternative to pretty much all of my web service so I can call them in the browser if needed for debugging purposes, however when I call them from code I still use camel case and it works fine.

    Maybe it's worth giving it a shot in your system? 

    Sascha

     

     

  • Julius Bartkus 51 posts 76 karma points
    Sep 04, 2010 @ 12:12
    Julius Bartkus
    0

    Well, it could be an option, but I don't want to cause problems to customers.

    Therefore I think there should be a fix for this.

    I have put an issue on codeplex tracking system. http://umbraco.codeplex.com/workitem/28123

    If anybody found any solutions, please share :)

Please Sign in or register to post replies

Write your reply to:

Draft