Calling WebService from JavaScript

Discussion in 'ASP .Net Web Controls' started by Danijel Valentic, Sep 28, 2004.

  1. Hello!

    I have a WebService called MyWebService with webMethod returnMyNumber(string
    like). Now I need to call it from JavaScript and get the returned DataSet.
    How can I do this?

    Thanks everyone
    Danijel Valentic, Sep 28, 2004
    #1
    1. Advertising

  2. you need behaviors for that
    start here
    http://msdn.microsoft.com/library/default.asp?url=/workshop/author/webservice/overview.asp

    --
    Regards,
    Alvin Bruney
    [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
    Got tidbits? Get it here... http://tinyurl.com/27cok
    "Danijel Valentic" <> wrote in message
    news:%...
    > Hello!
    >
    > I have a WebService called MyWebService with webMethod
    > returnMyNumber(string like). Now I need to call it from JavaScript and get
    > the returned DataSet. How can I do this?
    >
    > Thanks everyone
    >
    Alvin Bruney [MVP], Sep 29, 2004
    #2
    1. Advertising

  3. WebService Enhancements, which incorporates DIME protocol that you could use
    here... Free reom Microsoft... Check MSDN site.

    --
    RobertK
    { Clever? No just smart. }

    "Danijel Valentic" <> wrote in message
    news:#...
    > Hello!
    >
    > I have a WebService called MyWebService with webMethod

    returnMyNumber(string
    > like). Now I need to call it from JavaScript and get the returned DataSet.
    > How can I do this?
    >
    > Thanks everyone
    >
    >
    Robert Koritnik, Sep 29, 2004
    #3
  4. thnx Alvin. This page is OK, it has a lot of information, but there is
    one thing that bothers me...

    On the

    http://msdn.microsoft.com/library/default.asp?url=/workshop/author/webse
    rvice/overview.asp

    page is writen:
    "The WebService behavior is encapsulated in an HTC file. Therefore,
    before you begin using the behavior in your own Web pages, download the
    WebService HTC File and copy it to a folder in your Web project."

    The "WebService HTC File" is link to this page:

    http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/samples
    /internet/welcome.asp

    And now I don't understand this: I have my own WebService. Do I have to
    download the htc file anyway or not? Do I have to make my own htc
    file(and if so how )?

    And if I have to download it how? I don't know how to download from the
    http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/samples
    /internet/welcome.asp

    page.

    Thanks again

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Danijel Valentic, Sep 29, 2004
    #4
  5. Zivijo!

    Res je lepo videti se kaksnega Slovenca tukaj gor... :))



    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Danijel Valentic, Sep 29, 2004
    #5
  6. OK, I have downloaded the .htc file...

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Danijel Valentic, Sep 29, 2004
    #6
  7. Danijel Valentic

    Lee_Nover Guest

    > OK, I have downloaded the .htc file...

    from where ? couldn't find it .. the one in the article is archived and
    not available :/
    tnx (hvala :p)
    Lee_Nover, Sep 29, 2004
    #7
  8. I did what is writen on the microsoft pages. I have:

    <DIV ID="service" STYLE="BEHAVIOR:url(webservice.htc)"></DIV> (inside
    <body></body>),

    <script language="javascript">
    function init()
    {
    service.useService ("http://localhost/Beseda/VrniBesedo.asmx?
    WSDL", "vrniPodatkeWebService" );
    }
    </script> (inside <head></head>)

    and
    <body MS_POSITIONING="GridLayout" onload="init()">.


    But I get a error message:
    An error has occurred in the script on this page.
    Object does not support this property or method


    What's wrong?
    thnx




    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Danijel Valentic, Sep 29, 2004
    #8
  9. Danijel Valentic, Sep 29, 2004
    #9
  10. OK. Now I need to populate a dataGrid with the data in the dataSet the
    webservice returns...

    any idea?

    thnx


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Danijel Valentic, Sep 29, 2004
    #10
  11. Ni panike...

    but it would probably be better (for the sake of others) to talk in english
    or we will be warned. ;)

    --
    RobertK
    { Clever? No just smart. }


    "Danijel Valentic" <> wrote in message
    news:#...
    > Zivijo!
    >
    > Res je lepo videti se kaksnega Slovenca tukaj gor... :))
    >
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
    Robert Koritnik, Sep 29, 2004
    #11
  12. HTC is for your web service consumer application which will call the web
    service from the client side. Your web service app doesn't need the HTC.

    --
    RobertK
    { Clever? No just smart. }

    "Danijel Valentic" <> wrote in message
    news:e$...
    >
    >
    > thnx Alvin. This page is OK, it has a lot of information, but there is
    > one thing that bothers me...
    >
    > On the
    >
    > http://msdn.microsoft.com/library/default.asp?url=/workshop/author/webse
    > rvice/overview.asp
    >
    > page is writen:
    > "The WebService behavior is encapsulated in an HTC file. Therefore,
    > before you begin using the behavior in your own Web pages, download the
    > WebService HTC File and copy it to a folder in your Web project."
    >
    > The "WebService HTC File" is link to this page:
    >
    > http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/samples
    > /internet/welcome.asp
    >
    > And now I don't understand this: I have my own WebService. Do I have to
    > download the htc file anyway or not? Do I have to make my own htc
    > file(and if so how )?
    >
    > And if I have to download it how? I don't know how to download from the
    > http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/samples
    > /internet/welcome.asp
    >
    > page.
    >
    > Thanks again
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
    Robert Koritnik, Sep 29, 2004
    #12
  13. As far as I'm concerned, that's a more tough one. "Normally" web services
    return more simple types as DataSets. Updating DataGrid with it would be:
    1. VERY complicated thing to do, while changing the whole server control on
    the client could end up in complicated problems on the server side when the
    HTTP_POST occures. You should be VERY familiar how a DataGrid behaves to do
    this.
    2. Quite complicated client script to get the job done.

    Still it's possible, but I don't think that any of us is going to write this
    for you. Too many specifics and too much work with no real result. I
    seriously doubt that anyone would use it...

    Just a suggestion.

    If you have to update your DataGrid and are already calling a web service
    somewhere on some server you could easily just postback and do this on the
    serverside.

    Calling a webservice from the client is more meant to be used:
    1. with more simple types to update a small portion of the UI (a label, or a
    small amount of controls on the client) while a VERY SMALL amount of data is
    transfered back and forth instead of large data transfers of the whole
    pages, pictures etc.
    2. to transfer LARGE posts TO the server with other types of encoding than
    Base64 which makes a large post even more larger (transfering files using
    DIME instead of the normal way)

    --
    RobertK
    { Clever? No just smart. }

    "Danijel Valentic" <> wrote in message
    news:#$...
    >
    > OK. Now I need to populate a dataGrid with the data in the dataSet the
    > webservice returns...
    >
    > any idea?
    >
    > thnx
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
    Robert Koritnik, Sep 29, 2004
    #13
  14. Hello again!

    I've done everything I needed and now I have a new problem:

    I've realized the WebService as an undependent project.
    Than I've added the WebReference to it. Now I want to deploy my
    Application to the server and I get this error:

    ... webService is null or not an object.

    How can I deploy it?

    Thnx for all of your help, d

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Danijel Valentic, Oct 1, 2004
    #14
  15. There is a good example of this at

    http://www.c-sharpcorner.com/Code/2002/May/HTMLClient4WebServices.asp

    It shows the client and the server

    Here is the client:

    <SCRIPT language="JavaScript">
    var iCallID;

    function ExecuteWS()
    {

    iCallID = service.Calculator.callService("Add",num1.value,num2.value);
    }

    function onWSresult()
    {
    if((event.result.error)&&(iCallID==event.result.id))
    {
    var xfaultcode = event.result.errorDetail.code;
    var xfaultstring = event.result.errorDetail.string;
    var xfaultsoap = event.result.errorDetail.raw;
    document.writeln("ERROR. Method call failed!");
    document.writeln("Call ID:" + iCallID);
    document.writeln("Fault Code:" + xfaultcode);
    document.writeln("Fault String:" + xfaultstring);
    document.writeln("SOAP Data:" + xfaultsoap);
    }
    else if(event.result.error == false)
    {
    sum.value= event.result.value;
    }
    }
    </script>
    <body onload= "service.useService('http://localhost/site/code/testws.asmx?WSDL','Calculator');">
    <div id="service" style="behavior:url(webservice.htc)"
    onresult="onWSresult()">
    </div>


    Number : <input type="text" name='num1'\">
    Number : </td><td><input type="text" name='num2'\">
    Total:<input type="text" name='sum'\">
    <button OnClick="ExecuteWS()">Add Numbers</button>
    </body>


    You also need to download webservice.htc from MS at
    http://msdn.microsoft.com/archive/en-us/samples/internet/behaviors/library/webservice/webservice.htc



    "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message news:<>...
    > you need behaviors for that
    > start here
    > http://msdn.microsoft.com/library/default.asp?url=/workshop/author/webservice/overview.asp
    >
    > --
    > Regards,
    > Alvin Bruney
    > [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
    > Got tidbits? Get it here... http://tinyurl.com/27cok
    > "Danijel Valentic" <> wrote in message
    > news:%...
    > > Hello!
    > >
    > > I have a WebService called MyWebService with webMethod
    > > returnMyNumber(string like). Now I need to call it from JavaScript and get
    > > the returned DataSet. How can I do this?
    > >
    > > Thanks everyone
    > >
    Howard Rothenburg, Oct 1, 2004
    #15
  16. you just need to copy the .htc file to the webserver

    --
    Regards,
    Alvin Bruney
    [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
    Got tidbits? Get it here... http://tinyurl.com/27cok
    "Danijel Valentic" <> wrote in message
    news:...
    >
    >
    > Hello again!
    >
    > I've done everything I needed and now I have a new problem:
    >
    > I've realized the WebService as an undependent project.
    > Than I've added the WebReference to it. Now I want to deploy my
    > Application to the server and I get this error:
    >
    > .. webService is null or not an object.
    >
    > How can I deploy it?
    >
    > Thnx for all of your help, d
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
    Alvin Bruney [MVP], Oct 1, 2004
    #16
  17. Danijel Valentic

    David Guest

    I've posted question after question to various NG's about that fact that MS
    has "archived" webservice.htc, and what is the replacement? But haven't
    gotten any viable responses (unless you consider "use xmlHttp to transport
    your soap envelope" to be a "viable" alternative...arrrgh).

    But I continue to see people recommending the use of webservice.htc, while
    no one is questioning the wisdom of using an "archived" component for new
    development!

    So, is WSE the functional "replacement/successor" to what webservice.htc
    provides (or should I say "provideD")?

    David

    "Robert Koritnik" wrote:

    > WebService Enhancements, which incorporates DIME protocol that you could use
    > here... Free reom Microsoft... Check MSDN site.
    >
    > --
    > RobertK
    > { Clever? No just smart. }
    >
    > "Danijel Valentic" <> wrote in message
    > news:#...
    > > Hello!
    > >
    > > I have a WebService called MyWebService with webMethod

    > returnMyNumber(string
    > > like). Now I need to call it from JavaScript and get the returned DataSet.
    > > How can I do this?
    > >
    > > Thanks everyone
    > >
    > >

    >
    >
    >
    David, Oct 14, 2004
    #17
  18. Danijel Valentic

    Lee_Nover Guest

    Lee_Nover, Oct 14, 2004
    #18
  19. Danijel Valentic

    David Guest

    I KNOW where the webservice.htc component is located. We've used it for a
    couple of years now.

    The question was (and IS): what is the functional replacement for
    webservice.htc now that it has been "archived" (aka, "obsolete").

    David

    "Lee_Nover" wrote:

    > quoting robert's reply to my question:
    >
    > From here:
    >
    > http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/samples/internet/welcome.asp
    >
    > At the left you have to choose this:
    > *Web & Internet Samples,
    > *DHTML Behaviors Library
    > *WebService.
    >
    > Then you get the page on the right, and you have a link:
    > "Download WebService HTC File".
    >
    David, Oct 14, 2004
    #19
  20. Danijel Valentic

    Lee_Nover Guest

    > I KNOW where the webservice.htc component is located. We've used it for a
    > couple of years now.
    >
    > The question was (and IS): what is the functional replacement for
    > webservice.htc now that it has been "archived" (aka, "obsolete").



    oh .. sorry .. dunno
    Lee_Nover, Oct 14, 2004
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. batista
    Replies:
    1
    Views:
    895
    Laurent Bugnion
    Jan 26, 2006
  2. batista
    Replies:
    0
    Views:
    551
    batista
    Jan 26, 2006
  3. Peter Nordström

    Webservice calling a webservice.....Error

    Peter Nordström, Oct 21, 2003, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    151
    Peter Nordström
    Oct 21, 2003
  4. Calling a webservice from a webservice

    , Apr 19, 2005, in forum: ASP .Net Web Services
    Replies:
    2
    Views:
    141
  5. batista
    Replies:
    0
    Views:
    245
    batista
    Jan 26, 2006
Loading...

Share This Page