Coffeehouse Thread

20 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Calling webservices from JavaScript in IE and FF

Back to Forum: Coffeehouse
  • User profile image
    jsampsonPC

    Does anybody know of a good resource online that demonstrates how to call webservices from the client in IE and FF...I have only found IE-only examples that wouldn't work in firefox, and it's almost frustrating enough to make me want to spit nails!

    Jonathan

  • User profile image
    W3bbo

    The examples should be easily modifiable to comply with the standard DOM and other features. Can you post the problematic code?

  • User profile image
    jsampsonPC

    W3bbo wrote:
    The examples should be easily modifiable to comply with the standard DOM and other features. Can you post the problematic code?


    I don't yet have any problematic code. I'm looking for resources so I can get to writing some problematic code Tongue Out

  • User profile image
    Nullable

    This is probably an obvious reply (well, I think it would be)... but have you thought about using ASP.NET AJAX? Smiley

    http://www.singingeels.com/Articles/Consuming_Web_Services_With_ASPNET_AJAX.aspx

    (article of the day for today - 7/14/2007 on www.asp.net)

  • User profile image
    cloak13​PLAGUE

    jsampsonPC wrote:
    Does anybody know of a good resource online that demonstrates how to call webservices from the client in IE and FF...I have only found IE-only examples that wouldn't work in firefox, and it's almost frustrating enough to make me want to spit nails!

    Jonathan



    Here is an AWESOME book on ASP.NET AJAX which I'd recommend to use in this situation. Professional ASP.NET 2.0 Ajax covers the various topics in ASP.NET Ajax or as I've been calling it lately ajax.net just because it is shorter to type Smiley

    The authors provide a great overview from basic Javascript skills to how the Ajax networking features work. They have some sections dedicated to web services that taught me how to implement them from me not knowing really that much about JSON and nothing at all about implementing Web Services via Javascript.

    Hope that helps. I've been really in to this technology lately so if you have any questions let me know, I might be able to help.

    Tim

  • User profile image
    jsampsonPC

    Nullable & Cloak,

    My only reservation with using asp ajax is that I'm under the impression that you apply rules and actions to objects early instead of late. What I mean by that is, you drag a button out onto the screen, and then apply some asp ajax code to it.

    In my situation, I'm building a large form/menu once the page is processed. So NONE of my controls exist until the page is requested. So I have tons of stuff like:

    myStringBuilder.Append("<button value=""" & myDataReader("ButtonValue").ToString() & """ />")

    That is a very very simplified example of the type of stuff I'm doing, but I really only expect to build this page once...and then never post-back again afterwards.

    What I need to do is be able to call a webservice from that generated button, so that the user can perform backend-data-manipulation like updating records, etc.

  • User profile image
    littleguru

    ASP.NET ATLAS can be used in different ways. It offers also a javascript library that abstracts the browser differences away and allows you to call web services and stuff.

    You should have a look at the ATLAS docs.

    Sample: http://www.devx.com/dotnet/Article/32508

  • User profile image
    JChung2006

    jsampsonPC wrote:
    myStringBuilder.Append("<button value=""" & myDataReader("ButtonValue").ToString() & """ />")

    Just say no to building HTML with StringBuilders!  Don't do it!

    <button id="ThisButton" runat="server" value='<%# Eval("ButtonValue") %>' />

  • User profile image
    Ion Todirel

    JChung2006 wrote:
    
    jsampsonPC wrote:
    myStringBuilder.Append("<button value=""" & myDataReader("ButtonValue").ToString() & """ />")

    Just say no to building HTML with StringBuilders!  Don't do it!

    <button id="ThisButton" runat="server" value='<%# Eval("ButtonValue") %>' />
    and why is that? ya in some ways pages/controls are better structured in that way but i prefer anything instead of the evil Eval

  • User profile image
    cmanciero

    This might be what you are looking for. This is what I use when creating Ajax call to a webservices.


    var objXmlHttpRequest;

    function AjaxCall(url)
    {
       var webServiceUrl = url; //<YOUR WEBSERVICE URL>;
       try
       {
               objXmlHttpRequest = CreateXmlHttpRequest();
               objXmlHttpRequest.open("get", url, true);

               objXmlHttpRequest.onreadystatechange = function ()
               {
                    if(objXmlHttpRequest.readyState == 4)
                    {
                       if(objXmlHttpRequest.status == 200)
                       {
                            alert(objXmlHttpRequest.responseText);
                       }
                    }
               };

            objXmlHttpRequest.send(null);
        }
        catch(Error)
        {
          alert(Error);
        }
    }

    function createXmlHttpRequest()
    {
        // See if browser is not IE
        if(typeof XMLHttpRequest != "undefined")
        {
            return new XMLHttpRequest();
        }
        // Browser is IE
        else if(window.ActiveXObject)
        {
            //Add versions of Microsofts XMLHttp
            var arrMSVersions = ["MSXML2.XMLHttp.5.0",
                                 "MSXML2.XMLHttp.4.0",
                                 "MSXML2.XMLHttp.3.0",
                                 "MSXML2.XMLHttp",
                                 "Microsoft.XMLHttp"];
            // Loop through each version to see which one the user has
            for(var v = 0; v < arrMSVersions.length; v++)
            {
                try
                {
                    var objXmlHttp = new ActiveXObject(arrMSVersions[v]);
                    return objXmlHttp
                }
                catch (Error)
                {
                    // Go to next ms version
                }
            }
        }
        throw new Error("XMLHttp object could not be created");
    }

  • User profile image
    jsampsonPC

    cmanciero wrote:
    This might be what you are looking for. This is what I use when creating Ajax call to a webservices.


    var objXmlHttpRequest;

    function AjaxCall(url)
    {
    ...


    This looks promising - do you have any documentation with this?

  • User profile image
    jsampsonPC

    Something additional that I was thinking about is the security-aspect of calling these services from a client. In my application, the user logs in, and is able to select a previous state of a form. It then loads the form for them with their values, and allows them to change their selections. I want the selections to be updated asynchronously via javascript calls to the web services - but only for logged in users, and only on records they have access to.

    Is this as big of a security issue as I'm thinking?

  • User profile image
    Sven Groot

    cmanciero wrote:
            //Add versions of Microsofts XMLHttp
            var arrMSVersions = ["MSXML2.XMLHttp.5.0",
                                 "MSXML2.XMLHttp.4.0",
                                 "MSXML2.XMLHttp.3.0",
                                 "MSXML2.XMLHttp",
                                 "Microsoft.XMLHttp"];

    No!

    MSXML5 will already cause a warning in IE7 ("do you want to run this activex control?"), and MSXML4 is due to be disabled. Only use MSXML6 and MSXML3. No others.

    See here.

  • User profile image
    Sven Groot

    jsampsonPC wrote:
    Is this as big of a security issue as I'm thinking?

    The browser'll send cookies and WWW-Authenticate headers to the web service same as to a regular page, so security should be no different.

  • User profile image
    littleguru

    Sven Groot wrote:
    
    jsampsonPC wrote:
    Is this as big of a security issue as I'm thinking?

    The browser'll send cookies and WWW-Authenticate headers to the web service same as to a regular page, so security should be no different.


    Everything is plain text... You need to use SSL to encrypt stuff. Otherwise everybody can read it.

  • User profile image
    Zeus

    MooTools dude ... MooTools Big Smile

    I use this ALL the time, with great efficiency ... saves dev-time and has some great built in features.

  • User profile image
    jsampsonPC

    littleguru wrote:
    
    Sven Groot wrote:
    
    jsampsonPC wrote:
    Is this as big of a security issue as I'm thinking?

    The browser'll send cookies and WWW-Authenticate headers to the web service same as to a regular page, so security should be no different.


    Everything is plain text... You need to use SSL to encrypt stuff. Otherwise everybody can read it.


    What I'm concerned with is somebody being able to manually invoke a service, and change values in records for other people.

  • User profile image
    Harlequin

    Ion Todirel wrote:
    
    JChung2006 wrote:
    
    Just say no to building HTML with StringBuilders!  Don't do it!

    <button id="ThisButton" runat="server" value='<%# Eval("ButtonValue") %>' />
    and why is that? ya in some ways pages/controls are better structured in that way but i prefer anything instead of the evil Eval


    Because you don't put UI in your C#.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.