All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
PHP5中的this,self和parent关键字详解_php资料_编程技术
session简要用法实例_[Asp.Net教程]
使用Delphi组件编程
同步两个Sql,server(3)_[SQL,Server教程]
如何平衡营销型网站的用户体验设计和优化_优化技巧_seo学堂
SQLServer2005中的XML选项详解(1)_[SQL Server教程]
ASP.NET,2.0,中使用自定义缓存依赖_[Asp.Net教程]
十天学会ASP.net,第九天_.net资料_编程技术
从数据库导出数据到word、excel、.txt_[Asp.Net教程]
JS获取网页中HTML元素的几种方法分析_[Html教程]
Reading number is top 10 pictures
NeedWallpaper5
29 the belle stars after bath figure3
银行20年后可能消失
Sora aoi in China1
Female model behind the bitterness, often being overcharged5
Go to the national museum2
谁认识这位校花
Beautiful Japanese beauty(漂亮的日本美女)
Fat bird to fly
Sell the barbecue as says father du breul5
Download software ranking
Boxer vs Yellow5
I'm come from Beijing1
C++编程教程第三版
matrix1
传奇私服架设教程
ASP.NET.2.0.XML.高级编程(第3版)
Tram sex maniac 2 (H) rar bag3
Eclipse-CALMSANNY (second edition)
Take off clothes to survival
The hero
delv published in(发表于) 2014/1/6 8:46:47 Edit(编辑)
.net下用javascript调用webservice_[Asp.Net教程]

.net下用javascript调用webservice_[Asp.Net教程]

.net下用javascript调用webservice_[Asp.Net教程]























.net 下用javascript调用webservice的话,要用到webservice behavior。下面以一个例子讲解之,比较简单


1 、首先,要创建一个webservice,比如




<%@ WebService Language="C#" class=MyMath %>
using System;
using System.Web.Services;
public class MyMath {
[WebMethod]
public int add(int a, int b)
{
return a + b;
}
[WebMethod]
public int subtract(int a, int b)
{
return a - b;
}
}




  然后发布,先得到其wsdl。




  2、首先,我们要下载webbehavior.htc这个文件(可以到http://msdn.microsoft.com/downloads/samples/internet/behaviors/library/webservice/default.asp.)
去下载,然后放到你的web当前目录下然后在要调用webserice的页面中,修改如下













  这里我们将div id命名为有意义的名称,并且指定style为 webservice行为。接着,我们要书写javascript来调用webserice了:




  首先,我们在javascript中,调用其wsdladdservice.useService("http://localhost/services/math.asmx?WSDL","MyMath");使用id.useService(WSDLL路径,简单的命名方式);




  我们之前设定的id是addservice,而为了给客户端调用方便,我们这里起了名称,叫MyMath。而为了保证能正确调用webserice,必须在body里的onload事件里,马上加载处理webservice调用的javascript,如下















  在上面,我们通过webservice行为,首先得到了返回webservice的wsdl,接下来我们要进行调用了,调用的格式如下: iCallID = id.FriendlyName.callService([CallbackHandler,] "MethodName", Param1, Param2, ...);




  这里id是我们在div里设置的id,而FridndbyName是我们刚才为方面而起的命,这里就是MyMath了,而CallbackHandler是使用回调函数的过程名,如果无设置的话,则默认是使用onresult所调用的方法来进行处理,下文会讲到,而param1,,param2等则是说传入的参数了,如:















  注意,用onresult方式返回的话,要在div部分的onresult中指定处理的方法,这里是用onWsresult()方法,其中根据返回的信息来判断是否出错,出错的话则显示。




  如果用回调的话,则如下处理















来源:网络












































添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.