call asp.net webservice from html file with javascript through webservice.htc

Last post 07-22-2009 4:31 AM by Vince Xu - MSFT. 3 replies.

Sort Posts:

  • call asp.net webservice from html file with javascript through webservice.htc

    07-20-2009, 8:29 AM
    • Member
      6 point Member
    • keetje
    • Member since 05-14-2008, 11:43 AM
    • Posts 58

     Hi all,

    I have added a webservice to my asp.net website. Let's say /root/WebServices/webservice.asmx. with a codefile: /root/App_Code/webservice.cs.

    This works all just fine. I can invoke it calling it from a browser etx.

    Now I want to test it to call it from a simple html page. I have tested it locally and it works just fine.

    When I now test my local html file with the uploaded webservice it does not work and 'undefined' get's returned.

    Code I use in htmpage is:

    <html>
    <head>
        <title>webservice javascript</title>
        <script language="javascript" type="text/javascript">
            var callID = 0;
    
            function InitializeService(){
                    service.useService("http://www.mysite.nl/WebServices/webservice.asmx?wsdl", "webservice");
                }
                
            function LookupHTML()
                {
                    callID = service.webservice.callService("GetTextLastVote");
                }
                
            function LookupNumber()
                {
                    callID = service.webservice.callService("GetAorB", getal.value);
                }
    
            function ShowResult()
                {
                    resulthtml.innerHTML = event.result.value;
                }
    
        </script>
    </head>
    <body onload="InitializeService()" id="service" style="behavior:url(webservice.htc)" onresult="ShowResult()">get htmlcode: <input type="button" onclick="LookupHTML()" value="Klik hier"/>
        <br />Get number: <input id="getal" /> <input type="button" onclick="LookupNumber()" value="Geef een getal" />
        <br />
        <br />
        <div id="resulthtml" onresult="ShowResult()"></div>
    </body>
    </html>

    Anyone an idea what I am missing or doing wrong?

    Thanks!!

     

  • Re: call asp.net webservice from html file with javascript through webservice.htc

    07-20-2009, 9:23 AM
    • Participant
      930 point Participant
    • MisterFantastic
    • Member since 09-21-2008, 5:56 AM
    • Chennai
    • Posts 278

     Hi,

    You have to download the "Webservice.htc" from the following location and save in your projects folder.

    http://www.microsoft.com/downloads/details.aspx?familyid=1A3F25CA-0387-49A9-8EDC-B8BC0309A2E1&displaylang=en

    include in the html file reference like you refer a script.

    The other way to a webservice is using XMLHTTPRequest object or use a Javascritp library like jquery ,ASP.Net ajax client library or Dojo.

    Thanks,

    Thani

    Tao of Jeet Kune Do
  • Re: call asp.net webservice from html file with javascript through webservice.htc

    07-20-2009, 9:34 AM
    • Member
      6 point Member
    • keetje
    • Member since 05-14-2008, 11:43 AM
    • Posts 58

    Thanks for the reply. The webservice.htc file is already on the server... so that is not the problem... what could be? Please help..

  • Re: call asp.net webservice from html file with javascript through webservice.htc

    07-22-2009, 4:31 AM
    Answer

     Hi,

    Please use Ajax webservice http://dotnetslackers.com/columns/ajax/ASPNETAjaxWebService.aspx

    Then you don't need any utc file to support.

     


    Vince Xu
    Microsoft Online Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Page 1 of 1 (4 items)