webservice调用方法

一、WebService在cs后台程序中的调用      A、通过命名空间和类名直接调用           示例:                          WebService ws = new WebService();                  string s = ws.HelloWorld();     B、通过添加WEB引用的方式调用,首先添加WEB引用,通过URL指向WEBSERVICE,          指定WEB引用名,假设为KK;            示例:                   kk.WebService n = new kk.WebService();                   string ss=n.HelloWorld(); 二、WebService在前台页面的JS调用方法     1、首先通过下面的方法把Webservice在前台引用进来            <asp:ScriptManager ID="ScriptManager1" runat="server">                 <Services>                     <asp:ServiceReference Path="WebService.asmx" InlineScript="True" />                 </Services>             </asp:ScriptManager>     2、然后就可以通过JS程序进行调用,示例如下:          <script type="text/jscript">             function a()             {                WebService.HelloWorld(onresult);             }             //这里的onresult是回调函数             function onresult(result)            {               alert(result);            }            function b()            {               WebService.add(1,2,onreturn)            }            function onreturn(result)           {              alert(result);           }           //下面的'context'是上下文,可以通过回到函数通过重载的方式获得;           function c()          {              WebService.div(1,1,onresultC,onerror,'context');          }          function onresultC(res,c)         {              alert(res);              alert(c);          }          //onerror是获得异常信息的回调函数,下面给出了获得异常信息的方法          function onerror(error)          {             var a="";             a=String.format("获取服务器端异常的具体类型:{0}/t/n获取详细的异常描述信息:{1}/t/n获取造成异常的:{2}/t/n获取服务器端异常的堆栈                                     跟踪信息:{3}/t/n获取一个布尔值,表示异常是否是由于网络连接超时造成的{4}",             error.get_exceptionType(),             error.get_message(),             error.get_statusCode(),             error.get_stackTrace(),             error.get_timedOut())             alert(a);           }              a();           b();           c();         </script>        
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值