0

I have a requirement of calling a web service built in Java to be called from an HTML page via Java-script.

I have tried the code sample available at the following URL: http://www.codeproject.com/Articles/14610/Calling-Web-Services-from-HTML-Pages-using-JavaScr#

  <html>
  <head>
   <title>Hello World</title>
    <script language="JavaScript">
     var iCallID;
     function InitializeService(){
      service.useService(http://localhost:1394/MyWebService.asmx?wsdl, 
    "HelloWorldService");
      service.HelloWorldService.callService("HelloWorld");
     }
     function ShowResult(){
      alert(event.result.value);//Output: Undefined
     }
    </script>
   </head>
  <body onload="InitializeService()" id="service" 
    style="behavior:url(webservice.htc)" onresult="ShowResult()"> </body>
 </html>

The web service is running and has been tested via a Weblogic inbuilt test client.

Please suggest some JS code for calling a webservice with String Parameters

Fr_nkenstien
  • 1,923
  • 7
  • 33
  • 66
  • Vote to close. Please comment on why whatever you've posted as sample does not work for you. Also consider using more mainstream JQuery.ajax to make calls ( http://stackoverflow.com/questions/861784/how-to-call-a-web-service-from-jquery ) – Alexei Levenkov Apr 19 '12 at 06:06
  • Ugh, that code smells like IE-only... – ThiefMaster Apr 19 '12 at 06:07
  • The Line: service.useService(http://localhost:1394/MyWebService.asmx?wsdl, "HelloWorldService"); poses a problem. My Web Service never gets a hits and the request is lost in mid way. then the next line onwards, the code starts giving undefined for the response(Line: alert(event.result.value);) – Fr_nkenstien Apr 19 '12 at 08:33
  • Please suggest any other code that might help in calling a Web service from Java script with parameters and the WSDL URL is provided. – Fr_nkenstien Apr 19 '12 at 08:36

1 Answers1

0

Ajax. Be careful though, it only allows requests on the same domain (browsers limitation). If you want cross-domain support, either use JSONP (if the webservice allows it), or use a server as a proxy, so that:

Javascript -> Server on same domain -> WebService
Florian Margaine
  • 58,730
  • 15
  • 91
  • 116
  • Please provide Code Snippet so that i can try out the same. – Fr_nkenstien Apr 19 '12 at 08:37
  • AJAX is a vast subject, and I don't even know whether you need the snippet in javascript or not (cross-domain or not? jsonp allowed or not?). – Florian Margaine Apr 19 '12 at 12:00
  • Hi Florian Margaine, the thing is that i need to create a simple HTML page for demo purposes only and need to call the web-service through the HTML page. the simplest i guess will be javascript. Please help with the simplest possible solution – Fr_nkenstien Apr 19 '12 at 13:55