Help consuming web service on HTM page

Last post 06-06-2008 11:04 AM by pwrjng. 4 replies.

Sort Posts:

  • Help consuming web service on HTM page

    10-11-2007, 10:03 PM

    I' not even 100% sure if this is possible, but basically I want to use a JavaScript to get a value from a web service that I can use on a HTM page (Not an ASPX page). I have written the web service and AJAX enabled it, but Im not 100% sure of what scripts I need to include in my page to get it to work. I tried using:

    <script src=http://testsenapps1/ActiveDirectory.asmx/js type="text/javascript"></script>

     but that got me no where. Does this make sense to anyone else? Has anyone done anything like this before, is it even do-able? Its for a bit of a patch up job on an old website while a new one is in development, the webservice returns a display name of the current user, and it works fine.

     

     

  • Re: Help consuming web service on HTM page

    10-11-2007, 11:38 PM
    • Loading...
    • dhanabalanr
    • Joined on 09-23-2007, 1:38 PM
    • India
    • Posts 181

    Brain,

    pls go thru this

    http://aspalliance.com/713

    With Luv
    Dhana

    Dont forget to mark as answer if my reply helped you...



  • Re: Help consuming web service on HTM page

    10-13-2007, 7:40 PM

    First add the Framework Script MicrosoftAjax.js, then add the WS script like the way you are currently doing. The script manager also does the similar thing behind the scene.

    Long Live .NET
    Kazi Manzur Rashid (Amit)
    _________________________
    http://weblogs.asp.net/rashid/
  • Re: Help consuming web service on HTM page

    10-16-2007, 1:46 AM
    Answer

    Hi,

     

    Basically you can just use following code to consume the webservice:


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        <title>Untitled Page</title>
        <script src="MicrosoftAjax.debug.js"></script>
        <script src="WebService.asmx/js"></script>
        <script>
            function onReturn(result)
            {
                alert(result);
            }
        </script>
    </head>
    <body>
        <input type="button" onclick="WebService.HelloWorld(onReturn)" />
    </body>
    </html>

     

    However, due to an un-identified issue of the MicrosoftAjax.debug.js (or MicrosoftAjax.js), the returned result is using a different format. See a recent discussion thread “How to call web service in a html page?” in DL “Friend of Atlas”. It seems the standalone version of MicrosoftAjax.js is different from the one generated using ScriptManager. Following code in ASPX works correctly to show the returned string:


    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Untitled Page</title>
        <script>
            function onReturn(result)
            {
            alert(result);
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:ScriptManager ID="ScriptManager1" runat="server" >
                <Services>
                    <asp:ServiceReference Path="~/WebService.asmx" />
                </Services>
            </asp:ScriptManager>
            <div>
                <input type="button" onclick="WebService.HelloWorld(onReturn)" />
            </div>
        </form>
    </body>
    </html>

    According to this comment:

            There was a change in how objects are sent over the wire: returning a string will actually return an object with one property whose value is a string:  {“d”:”Hello World”}.  The older script library didn’t expect that, and that’s why you got [object Object].

            Thanks,
            Leonid

            -------------------


            We should make the HTMLPage work by:

     

            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
            <html xmlns="http://www.w3.org/1999/xhtml" >
            <head>
                <title>Untitled Page</title>
                <script src="MicrosoftAjax.debug.js"></script>
                <script src="WebService.asmx/js"></script>
                <script>
                    function onReturn(result)
                    {
                        alert(result["d"]);
                    }
                </script>
            </head>
            <body>
                <input type="button" onclick="WebService.HelloWorld(onReturn)" />
            </body>
            </html>

     

            But I haven’t found documentation on this behavior so far, you can dig more to find out.

    Best Regards,

    Sincerely,
    Jin-Yu Yin
    Microsoft Online Community Support
  • Re: Help consuming web service on HTM page

    06-06-2008, 11:04 AM
    • Loading...
    • pwrjng
    • Joined on 05-22-2003, 6:36 PM
    • Posts 19

    Hi,Jin-Yu Yin - MSFT

    Like you said, when i call alert(result);
    it gives me [object Object] instead of the string.

    Which script library should i update in order to solve this problem?

    Thanks. 

Page 1 of 1 (5 items)
Microsoft Communities
Page view counter