Calling WebServices using Javascript

If you are using Microsoft IE 5 or later, you can use the behavior/HTML-Component "WebService" to access a Web service. The "WebService" behavior communicates with Web services over HTTP using Simple Object Access Protocol (SOAP).

To use the "WebService" behavior, you must attach it to an element using the STYLE attribute, as follows:

<DIV ID="GiveItAName"
STYLE="behavior:url(webservice.htc)"></DIV>

A complete example taken from the Microsoft Web site is as follows:

<html>
<head>
<script language="JavaScript">
var iCallID;

function init()
{
service.useService
("
http://myserver.com/services/myservice.asmx?WSDL",
                   "servicename");
}

function onmyresult()
{
   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;

      // Add code to output error information here
      alert("Error ");
   }
   else
   {
      service.innerHTML= "The method returned the result: "
                         + event.result.value;
   }
}
</script>
</HEAD>
<body οnlοad="init();">
<BR>
Enter a Value <input type='text' id='param1'>
<BR>
<button οnclick='iCallID = service.servicename.callService
("ProcedureName", param1.value);'>Call A Web Method</button>
<div id="service"
     style="behavior:url(webservice.htc)"
     onresult="onmyresult();">
</div>
</body>
</html>

source: http://weblogs.asp.net/Varad/archive/2004/06/14/155671.aspx

posted on 2004-06-15 18:47 ccBoy 评论(3) 收藏

href="http://www.cnblogs.com/ccboy/Services/Pingback.aspx" rel="pingback">

评论

# re: Calling WebServices using Javascript 2004-06-15 21:15 hBifTs

呵呵,是的,以前也看到过:)

# re: Calling WebServices using Javascript 2004-06-16 20:49 ccBoy

其实这篇更好
Remote Scripting in a .NET World
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnclinic/html/scripting11122001.asp

Scripting Web Services
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnclinic/html/scripting03132000.asp

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值