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

Reading number is top 10 articles
SQL子查询实例介绍_[SQL Server教程]
delphi类的多态性
SQL,SERVER中字段类型及说明_mssql学习_编程技术
ASP.NET中“找不到指定模块”的解决办法_[Asp.Net教程]
将ASP.NET,Control转换为String_[Asp.Net教程]
C#教程:C#2.0 新特性 局部类
轻松了解-SQL Server 2008-的报表服务_[SQL Server教程]
visual c++中控件的概述
PHP实例:用PHP实现XML备份Mysql数据库_[PHP教程]
C#随机生成汉字验证码代码_[Asp.Net教程]
Reading number is top 10 pictures
到南昌西站了2
Look at the Spring Festival people crowded into the what kind
ashlynn brooke
大人物的礼物
青涩甜美-王祖贤小时候的旧照片曝光
世界五大海盗
网上疯传的一篇小学作文《爸爸也治不了妈妈》
Angie Chiu vijara myth2
Chinese paper-cut grilles art appreciation3
福利福利。。。。。。
Download software ranking
Love the forty days
Boxer's Top ten classic battle2
都市狐狸姑娘传
jBuilder2006
Be there or be square
WebService在.NET中的实战应用教学视频 → 第1集
双旗镇刀客B
终极变速大师Speeder3.26
White deer villiage
软件工程思想
归海一刀 published in(发表于) 2014/1/30 0:52:07 Edit(编辑)
Asp.Net,Ajax,学习笔记8,客户端访问WebService(下)_[Asp.Net教程]

Asp.Net,Ajax,学习笔记8,客户端访问WebService(下)_[Asp.Net教程]

Asp.Net Ajax 学习笔记8 客户端访问WebService(下)_[Asp.Net教程]

1、改变客户端访问WebService代理方法名


客户端无法重载函数,只能根据arguments的参数来判断。并且不能根据参数的类型来判断
如果WebService端有函数的重载,这时候映射到客户端是无法区别的。那么我们需要把函数的重载在客户端映射成非重载函数。在WebService方法上添加一个[WebMethod(MessageName = “…")]这样一个标记 [WebMethod]
public int GetRandom()
{
return new Random(DateTime.Now.Millisecond).Next();
}


[WebMethod(MessageName="GetRangeRandom")]
public int GetRandom(int minValue, int maxValue)
{
return new Random(DateTime.Now.Millisecond).Next(minValue, maxValue);
}如例所示,那么有两个参数的GetRandom方法映射到客户端就是GetRangeRandom方法了。当然,不一定是重载时才能改变方法名,但是在重载时改变方法名才能体现这个标记的意义。
2、使用Http的Get方式访问WebService的方法


使用Get方式访问WebService的方法,必须加上[ScriptMethod(UseHttpGet=true)]标记 [WebMethod]
[ScriptMethod(UseHttpGet=true)]
public int GetRangeRandom(int minValue, int maxValue)
{
return new Random(DateTime.Now.Millisecond).Next(minValue, maxValue);
}
参数将使用QueryString进行传递
性能较HTTPPOST方法略有提高
3、让方法返回XML对象


客户端调用WebService方法默认使用JSon字符串返回数据。
要返回XML对象必须给ScriptMethod标记加上ResponseForma=ResponseFormat.Xml参数
Response的Content-Type将被设置为text/xml
返回普通对象时将使用XmlSerializer输出,如上面例子中返回Employee
返回字符串时可以直接作为XML字符串输出,就是说就算给出XML结构类似的字符串,经过XmlSerializeString处理之后,会将<和>转义,并且根元素为string //输入的XML结构的字符串
hello


//被XmlSerializeString处理后输出的字符串,根元素为string,<>被转义
&lt;xml&gt;hello&lt;/xml&gt;


4、在WebService方法中使用Session


在WebMethod标签中加入EnableSession=true参数 [WebMethod(EnableSession = true)]
public int AddOne()
{
HttpSessionState session = HttpContext.Current.Session;
object objValue = session["value"];
int value = objValue == null ? 0 : (int)objValue;
value++;
session["value"] = value;
return value;
}
5、在客户端调用WebService的安全性


完全适应Asp.Net的认证机制
可以使用FormsAuthentication,让WebService方法可以操作Cookie
Impersonation
PrincipalPermission
6、不使用WebService代理的对应方法,使用客户端代理直接调用WebService方法。


Invoke方法签名
Sys.Net.WebServiceProxy.invoke= function (
servicePath,/*Service路径*/
methodName,/*方法名*/
useGet,/*是否使用HTTPGET方法*/
params,/*方法参数*/
onSucceeded,/*成功后的回调函数*/
onFailure,/*失败后的回调函数*/
userContext,/*用户上下文对象*/
timeout /* 超时时间*/){ } function getRandom(minValue, maxValue)
{
Sys.Net.WebServiceProxy.invoke(
"Services/UseHttpGetService.asmx",
"GetRangeRandom",
true,
{ "minValue" : minValue,
"maxValue" : maxValue},
onSucceeded,
null,
null,
-1);
}


对应上面的invoke参数说明和例子,对WebService生成的代理方法是如何调用WebService有一定了解







添加到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.