需要使用到的一个文件:http://www.cimarmx.com/elbebe/archivos/webservice.htc
以下是html页面代码,web service的具体代码省略了
页面加载调用的情况:
Code
1 <html>
2 <head>
3 <title>Hello World</title>
4
5 <script language="JavaScript">
6 function InitializeService()
7 {
8 //HelloWorldService是随便命名,HelloWorld是web method
9 service.useService("http://localhost:1554/MyWebService.asmx?wsdl", "HelloWorldService");
10 service.HelloWorldService.callService("HelloWorld");
11 }
12
13 function ShowResult()
14 {
15 alert(event.result.value);
16 }
17 </script>
18
19 </head>
20 <body onload="InitializeService()" id="service" style="behavior: url(webservice.htc)"
21 onresult="ShowResult()">
22 </body>
23 </html>
24
事件触发调用:
Code
1 <html>
2 <head>
3 <title>Hello World</title>
4
5 <script language="JavaScript">
6 function callWebService()
7 {
8 service.useService("http://localhost:1554/MyWebService.asmx?wsdl", "HelloWorldService");
9 service.HelloWorldService.callService(callBack,"HelloWorld");
10 }
11
12 function callBack(res)
13 {
14 alert(res.value);
15 }
16 </script>
17
18 </head>
19 <body id="service" style="behavior: url(webservice.htc)">
20 <a href="#" onclick="callWebService();">Call</a>
21 </body>
22 </html>
23
代码不太雅观,需要加载htc文件,50多k。 还有更好的实现方法吗?