- 浏览: 7861136 次
- 性别:
- 来自: 广州
文章分类
- 全部博客 (2425)
- 软件工程 (75)
- JAVA相关 (662)
- ajax/web相关 (351)
- 数据库相关/oracle (218)
- PHP (147)
- UNIX/LINUX/FREEBSD/solaris (118)
- 音乐探讨 (1)
- 闲话 (11)
- 网络安全等 (21)
- .NET (153)
- ROR和GOG (10)
- [网站分类]4.其他技术区 (181)
- 算法等 (7)
- [随笔分类]SOA (8)
- 收藏区 (71)
- 金融证券 (4)
- [网站分类]5.企业信息化 (3)
- c&c++学习 (1)
- 读书区 (11)
- 其它 (10)
- 收藏夹 (1)
- 设计模式 (1)
- FLEX (14)
- Android (98)
- 软件工程心理学系列 (4)
- HTML5 (6)
- C/C++ (0)
- 数据结构 (0)
- 书评 (3)
- python (17)
- NOSQL (10)
- MYSQL (85)
- java之各类测试 (18)
- nodejs (1)
- JAVA (1)
- neo4j (3)
- VUE (4)
- docker相关 (1)
最新评论
-
xiaobadi:
jacky~~~~~~~~~
推荐两个不错的mybatis GUI生成工具 -
masuweng:
(转)JAVA获得机器码的实现 -
albert0707:
有些扩展名为null
java 7中可以判断文件的contenttype了 -
albert0707:
非常感谢!!!!!!!!!
java 7中可以判断文件的contenttype了 -
zhangle:
https://zhuban.me竹板共享 - 高效便捷的文档 ...
一个不错的网络白板工具
.net 下用javascript调用webservice的话,要用到webservice behavior。下面以一个例子讲解之,比较简单
1 、首先,要创建一个webservice,比如
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的页面中,修改如下
<body> <div id="addservice" style="behavior:url(webservice.htc)"></div> </body>
这里我们将div id命名为有意义的名称,并且指定style为 webservice行为。接着,我们要书写javascript来调用
webserice了:
首先,我们在javascript中,调用其wsdl
addservice.useService("http://localhost/services/math.asmx?WSDL","MyMath");
使用id.useService(WSDLL路径,简单的命名方式);
我们之前设定的id是addservice,而为了给客户端调用方便,我们这里起了名称,叫MyMath。
而为了保证能正确调用webserice,必须在body里的onload事件里,马上加载处理webservice调用的javascript,
如下
<script language="JavaScript"> function init() { addservice.useService("http://localhost/services/math.asmx?WSDL","MyMath"); } </script> <body onload="init()"> <div id="service" style="behavior:url(webservice.htc)"> </div> </body>在上面,我们通过webservice行为,首先得到了返回webservice的wsdl,接下来我们要进行调用了,
调用的格式如下:
iCallID = id.FriendlyName.callService([CallbackHandler,] "MethodName", Param1, Param2, ...);这里id是我们在div里设置的id,而FridndbyName是我们刚才为方面而起的命,这里就是MyMath了,而CallbackHandler
是使用回调函数的过程名,如果无设置的话,则默认是使用onresult所调用的方法来进行处理,下文会讲到,而param1,
,param2等则是说传入的参数了,如:
<SCRIPT language="JavaScript"> // All these variables must be global, // because they are used in both init() and onresult(). var iCallID = 0; var intA = 5; var intB = 6; function init() { // Establish the friendly name "MyMath" for the WebServiceURL service.useService("/services/math.asmx?WSDL","MyMath"); // The following method doesn't specify a callback handler, so onWSresult() is used iCallID = service.MyMath.callService("add", intA, intB); } function onWSresult() { // if there is an error, and the call came from the call() in init() if((event.result.error)&&(iCallID==event.result.id)) { // Pull the error information from the event.result.errorDetail properties var xfaultcode = event.result.errorDetail.code; var xfaultstring = event.result.errorDetail.string; var xfaultsoap = event.result.errorDetail.raw; // Add code to handle specific error codes here } // if there was no error, and the call came from the call() in init() else if((!event.result.error) && (iCallID == event.result.id)) { // Show the arithmetic! alert(intA + ' + ' + intB + ' = ' + event.result.value); } else { alert("Something else fired the event!"); } } </SCRIPT> <body onload="init()"> <div id="service" style="behavior:url(webservice.htc)" onresult="onWSresult()"> </div> </body>注意,用onresult方式返回的话,要在div部分的onresult中指定处理的方法,这里是用onWsresult()方法,
其中根据返回的信息来判断是否出错,出错的话则显示。
如果用回调的话,则如下处理
<SCRIPT language="JavaScript"> // All these variables must be global, // because they are used in both init() and onResult(). var iCallID = 0; var intA = 5; var intB = 6; function init() { // Establish the friendly name "MyMath" for the WebServiceURL service.useService("/services/math.asmx?WSDL","MyMath"); // The following uses a callback handler named "mathResults" iCallID = service.MyMath.callService(mathResults, "add", intA, intB); } function mathResults(result) { // if there is an error, and the call came from the call() in init() if(result.error) { // Pull the error information from the event.result.errorDetail properties var xfaultcode = result.errorDetail.code; var xfaultstring = result.errorDetail.string; var xfaultsoap = result.errorDetail.raw; // Add code to handle specific error codes here } // if there was no error else { // Show the arithmetic alert(intA + ' + ' + intB + " = " + result.value); } } </SCRIPT> <body onload="init()"> <div id="service" style="behavior:url(webservice.htc)"> </div> </body>
发表评论
-
.NET 嵌入式版4.2发布:关键更新抢先看
2012-02-22 14:57 1842作为.NET家族的一员,.Net Micro Framewor ... -
asp.net中模拟测试smtp发信
2011-03-20 18:47 1880在asp.net 中,有时要测试发信SMTP,但如果在单元测试 ... -
vs.net 2010两个数据库方面的好工具
2011-02-14 11:47 1854今天发现vs.net 2010在处理数据库方面的两个不错的工具 ... -
将gridview导出到excel,world,pdf的小结
2011-02-07 22:47 2961下面小结下把gridview的数据导出到excel,world ... -
gridviewtips1:gridview的页脚中的加亮显示和页数显示
2011-01-27 09:58 2361在asp.net 中,要经常显示gridview中的页数,并且 ... -
asp.net 4中的HTML过滤的一个新特性
2011-01-21 09:47 1864在asp.net 4中,有个新增加的对HTML过滤,防止XSS ... -
在vs.net 2010中使用重构方法
2011-01-20 16:55 2164在vs.net 2010中,可以很方便地对一些冗余的代码进行重 ... -
一个比较好的.net 3.5的异常报告类
2011-01-10 14:51 1952发现了一个比较好的异常报告类,其中用到了.net 3.5以上的 ... -
asp.net 4.0中menu菜单的改进
2011-01-03 22:47 2574在asp.net 3.5时,如果用menucontrol时,使 ... -
asp.net 4中的新特性之一:控制URL长度
2010-09-14 23:06 2392asp.net 4中的新特性之一:控制URL长度。在ASP.N ... -
vs.net 2010中使用code snippets
2010-09-09 20:58 1581其实在vs.net 2010中,使用code snippets ... -
百万开发者拥戴!七大.NET著名开源项目
2010-09-07 09:42 2294新翻译了篇帖子,原文发表在 http://publish.i ... -
asp.net 2010中jquery调用webservice
2010-08-30 22:21 2760在asp.net 2010中,在建立web应用时,默认已经在s ... -
.net中的placeholder控件
2005-01-15 20:00 1935最近留意到有人问,NET中的placeholder控件用来做什 ... -
asp.net 中一次性更新DATAGRID中所有记录
2005-01-15 20:03 947在asp.net中,如何一次性 ... -
在asp.net 中实现只允许数字输入的文本框
2005-01-15 20:18 1495在asp.net 中实现只允许数字输入的文本框,其实是十分简单 ... -
一个重构代码的小技巧
2005-01-16 21:58 1140刚开始接触重构,听就听的多了,理论没认真看过,不过今天发现,将 ... -
防止SQL注入攻击
2005-02-05 14:42 1149看了本期ASP。NET杂志里的一篇讲防止SQL注入攻击的文章, ... -
优秀.net 控件包介绍
2005-02-18 19:47 1681在oday上看到得,将介绍摘录在这里 NetAdvantage ... -
vs.net 2005中的ConfigurationManager
2005-05-06 18:11 1641vs.net 2005中的ConfigurationManag ...
相关推荐
使用javascript 中Ajax技术调用WebService,包括JSP和ASP.NET中两种,其中JSP的WebService使用了XFire框架。 ASP.NET中的WebService做了一个方法示例GetProgress,包含3个参数。 JSP中的WebService做了hello方法的...
使用JavaScript直接调用Web Service是微软AJAX Extension支持的新特性,在Visual Studio 2005中如果不安装AJAX Extension是不能用的,而AJAX Extension是Visual Studio 2008的标准配置。 由于JavaScript是所有主流...
从ASP3.0和JavaScript调用WebService
二、如果需要启动 客户端 exe程序,则可以考虑使用javascript脚本。 三、案例项目说明 ConsoleAppMain:本案例中需要启动的服务端exe代码 asp.net:本案例中的asp网页代码,启动exe程序的代码在 Default.aspx.cs...
本示例是用微软提供的webservice.htc来完成的,当然用ASP.NET AJAX也能实现,但该示例全部是JAVASCRIPT来做的,简单明了.
体验.net 2.0 的优雅(1) -- 异步WebService调用 ASP.NET 2.0页面框架的几点新功能 ASP.NET 2.0 中收集的小功能点 asp.net2.0中的webpart使用小记 2.0问题、错误解决办法 ASP.NET 2.0使用Web Part创建应用程序之二...
首先,用VS2008创建一个asp.net网站 其次,项目 右键—>添加新项—>Web 服务 如下图: 就会产生WebService.cs和WebService.asmx两个文件 在WebService.cs中添加代码: 代码如下: using System; using System....
javascript脚本调用webService服务用来显示各式各样的统计报表效果图, 用户也可以录入金额重新进行报表的统计。 里面的统计统计报表效果图 种类繁多(主要包括柱状图、折线图、饼状图、环形图等),展示的效果也很 ...
用Jquery中Ajax方式在asp.net开发环境中WebService接口的调用 2、出现的问题 原因分析:浏览器同源策略的影响(即JavaScript或Cookie只能访问同域下的内容); 3、解决方案: (1) JSONP:只支持GET方式 (2) CROS:...
快速生成javascript代码来调用.Net WebService(.asmx)。 在 Visual Studio 2012 的 javascript 端完全支持自定义对象的智能感知。 易于使用,通过 JSON 传递参数。 在 Javascript 方面有相同的经验,比如在 C# ...
14.2.5 异步调用webservice 274 14.3 wcf开发 276 14.3.1 定义wcf服务契约和引入 14.3.1 wcf服务契约 277 14.3.2 构架wcf服务,运行wcf 14.3.1 服务 281 14.3.3 生成wcf服务代理的 14.3.1 代码文件 283 ...
1. ASP.NET AJAX 中,如何用 JavaScript 调用服务器端的方法? 这里不是指调用简单的 PageMethod,因为静态方法是不能操作当前页面的控件的,所以静态的 PageMethod 作用就跟普通的 WebService 一样,比较局限。 ...
书中提供了大量的实例,可帮助读者快速掌握如何在.NET平台下开发功能强大的ASP.NET应用程序。本书适合有一些基础的ASP.NET初级程序员以及准备迁移到ASP.NET 2.0的编程老手。该书与《ASP.NET 2.0入门经典(第4版)》...
远程逻辑调用,remoing接口只能用在.net中 13.什么是code-behind技术 aspx and cs 14.概述三层结构体系 web/business/dataaccess 15.asp.net如何实现MVC模式,举例说明! web/business/dataaccess ---------...
书中提供了大量的实例,可帮助读者快速掌握如何在.NET平台下开发功能强大的ASP.NET应用程序。本书适合有一些基础的ASP.NET初级程序员以及准备迁移到ASP.NET 2.0的编程老手。该书与《ASP.NET 2.0入门经典(第4版)》...
1. ASP.NET AJAX 中,如何用 JavaScript 调用服务器端的方法? 这里不是指调用简单的 PageMethod,因为静态方法是不能操作当前页面的控件的,所以静态的 PageMethod 作用就跟普通的 WebService 一样,比较局限。 ...
.NET源码,Ajax相关,Ajax,级联菜单 使用ajax技术结合c#的WebService实现的无刷新盛市、县三级联动下拉框源程序,含控件源代码,工程运行VS2003,具体一点就是使用webservice.htc,然后由JavaScript调用WebService来...
从功能的角度来看,WCF完全可以看作是ASMX,.Net Remoting,Enterprise Service,WebService,MSMQ等技术的并集。 WPF是Windows Presentation Foundation,微软新发布的Vista操作系统的三大核心开发库之一,其主要...