精彩的人生

好好工作,好好生活

BlogJava 首页 新随笔 联系 聚合 管理
  147 Posts :: 0 Stories :: 250 Comments :: 0 Trackbacks

#

六度分割是这样的理论:所谓六度分割理论是指six degrees of separation,是在20世纪60年代由哈佛大学心理学家 stanley milgram提出的,six degrees of separation,六度分割。简单来说,六度分割就是在这个社会里,任何两个人之间建立一种联系,最多需要六个人(包括这两个人在内),无论这两个人是否认识,生活在地球的任何一个地方,他们之间只有六度分割。

第一次听说六度理论的时候大约在一年以前,听说后没有多久,就参加了朋友火炬的“六度买车票实验”,实验的方法是我们把MSN名字改为原名+“请朋友们都把名字包含着句话:"求购19,20日北京到南宁t5车次卧铺2张,请联系139110xxxxx")”,开始的时候速度很慢,只有我们几个人改了名字,慢慢的越来越多的人改了名字,最后一天过后,虽然没有完全成功,但是结果非常接近。这个实验让我们体会到了六度的力量。

后来,我们发现了越来越多的SNS网站,他们的旗号都是遵循六度的原则,开始都让我们很兴奋,一个阶段里面我们几乎实验了能看到的所有的SNS网站,然而最后我们都离开了这些网站。他们没有给我们带来任何的便捷和好处。这让我一再反思六度理论。

再后来,在365kit上线之后,我很久没见的朋友LLF非常兴奋的认为365kit是实现六度思想的一个很好的载体,我们在msn上面进行了简单的讨论,发现大家有很多不太相同的看法,于是相约在七夕之夜,边吃边聊。长谈之后,LLF接受了我的很多观点,并说收益匪浅。然而在我看来,他对我启发也良多,尤其是那天我们说过的东西,是我思索了很久的,但是一直没有机会串连在一起的东西,我们的长谈让我思维中很多零碎的东西变得更加条理化,所以这篇文章很大一部份要归功于他。

特别需要说明的是,本文不是在说明六度是错误的理论,而是在讨论,在我们的SNS实践中,六度是不是完整的可以作为指导的思想。我的看法是六度作为SNS的指导原则,并不足够,还有很多残缺,这些残缺会给我们的SNS实践带来失败的结果。

1、残缺的六度

六度虽然是个社会学的理论,但是实际上它更像一个数学理论,很多人说六度和四色问题有异曲同工之妙。在我看来,六度理论很好的阐述了在一个网状结构(我们的人类社会)下,不同节点之间的联系和连接关系,然而它并不完整,并不足以指导我们的实践。

(1)关系的强弱——权值问题
首先六度肯定了人与人之间的普遍联系,但是没有对这种联系作定量分析。我们一生可能会认识千百人,他们有的对我极其重要,有的对我无足轻重,我们联系的建立的原因和方法也是千差万别,有父母亲属这类生而固有的联系,也有因为地理位置接近发展出来的,如邻里关系,还有因为共同学习生活而发展出来的同学、同事关系。六度理论中只把他们统统归结于联系,没有强弱之分。在网状结构里面,人与人的关系,需要加权处理,在这里,六度是残缺的。

(2)到达和建立联系的区别——目的和结果问题
20世纪60年代,耶鲁大学的社会心理学家米尔格兰姆(Stanley Milgram)就设计了一个连锁信件实验。他将一套连锁信件随机发送给居住在内布拉斯加州奥马哈的160个人,信中放了一个波士顿股票经纪人的名字,信中要求每个收信人将这套信寄给自己认为是比较接近那个股票经纪人的朋友。朋友收信后照此办理。最终,大部分信在经过五、六个步骤后都抵达了该股票经纪人。六度分割(也叫“六度空间”)的概念由此而来。这个故事很多六度的爱好者都知道,并奉为圣经。但是我请大家注意这个故事和我们现在流行的SNS网站的理念的重要查别。在这个故事里面,信到达了波士顿股票经纪人手里面没错,但是请注意整个过程中,每个人的朋友关系都没有发生改变。对,这点很重要,这个故事里面传递的信息,而我们现在看到的SNS网站希望在用户之间传递的是什么呢?是联系方式是朋友关系。
说到这里想提一下前面提到的火炬的买车票的实验,在那个实验里面,传递的实际上也是信息,而不是朋友关系。

(3)传递的成本和激励——阻尼问题
在Stanley Milgram的实验和火炬的实验里面,都没有任何的花费,或者说看起来成本为0。但是是不是真的成本为0呢?每个人传递一下信件花费极低,改下msn名字更是没有成本,然而那些人肯这么做,其实是看着朋友的面子上,所以这里花费的成本实际是什么呢?是中国人说的人情债,所谓的关系成本。没有人喜欢一个整天都要人帮忙这帮忙那的人,人情债和金钱债一样,背了就一定要还,这就是传递中的成本问题。火炬的火车实验后,我们一直在想这个问题,今天我们急需车票,可以请朋友们改他们的名字,但是我们能不能天天都用这种方法来找人帮忙呢?今天买车票,明天买球票,也许一次两次可以,次数多了,朋友们肯定会觉得厌烦,甚至放弃你这个朋友。

Gmail的邀请方式直至今日仍被很多人称颂,刚刚出现的时候,一个邀请甚至可以卖到60美金。很多人惊呼这是最伟大的营销。然而,到了今天,很多人的邀请已经变得无法送出去。为什么呢?因为一开始的时候Gmail是稀缺物品,所以价值高昂,加上Gmail带有Google的强势品牌和高度用户认同感,所以就更加被追捧,拥有Gmail成了荣誉的象征。这是这种荣誉成为了Gmail邀请在六度网络中疯狂传播的激励。然而随着Gmail的高度普及,这种荣誉感逐步下降,最终降低了激励,从来使传播陷入了停滞状态。

阻尼是好还是坏?没有阻尼我们可以给任何人发送信息,每个SNS网站都在宣扬你只需要六度就可以认识克林顿可以认识盖茨,但是有几个人真的去认识他们了?是因为他们不值得认识么?不是,是因为联系虽然看起来只有六度,然而每度的阻尼都有可能都是无法跨越的。但是你不要悲观,如果没有阻尼也许你会更加不爽!LLF算过“举例来说吧。假设每个人有30个朋友,信息经过六度是30的6次方 =729000000,数量足够到达一个能够覆盖所有可能的人的级别。”,如果六度的连接没有任何的阻尼,估计我们每天收到的来自六度好友的各种各样的信息就会让我们的脑袋爆炸。

在我们的生活里面,一个身份越高的人,越有名的人他就会有越多的好友,于是他也就越不想随便拓展自己的关系圈子,因为他们往往不胜其扰。前些日子的600演艺名人联系方式泄露事件就是一个例子,本来我们作为社会一分子都和这600名人有着六度的联系,然而某天因为他们的联系方式被公开,他们和我们的联系立刻被扁平化变成了一度。一瞬间,阻尼消失了,你可以随便打电话给那英、田震了,你不是想跟冯小刚聊电影么?你现在可以打电话了。但是,我们只能说结果这成了一场灾难,很多名人诉苦,说很多人打电话到他们的家里,说了句“你是XXX么?我很喜欢你!”然后就挂了电话。很多人不堪其扰停了机,甚至换了号。

这场灾难对我们这些局外人来说是一个很有意思的故事,很有趣的一点在于此,一旦这些名人和大众的关系扁平化后(六度变成一度),他们对大众的价值也开始流失,大众们只能打电话过去,问一声,然后炫耀自己给明星打过电话,仅此而已。这个巨大的扁平化工程并没有扩展追星族们的朋友圈子,他们仍旧离那些明星很远……

(4)朋友的朋友是朋友的假设——关系的方向和传递问题
 SNS网站最爱说的一句话也许就是“朋友的朋友是朋友”,然而那天我跟LLF在Msn聊天的时候就说过这个问题,我认识的某A的朋友某B是我非常反感的一个家伙,而且我的朋友里面还有个人某C对那个家伙某B更加痛恨。所以在现在的SNS服务里面我是不敢把某A和某C同时引入的,因为他们同时引入后,很可能的结果是某B和某C建立联系后,开始吵架。

2年前,我创办了Mop天津联盟,开始的时候是蜜月,那时候认识的朋友很多至今还是我很好的朋友,虽然我已经离开天津良久了。然而随着联盟的扩大,每次聚会的人数越来越多,关系越来越复杂,我们发现小圈子一旦扩大,人数一多,里面就会出现矛盾。不管我们怎么去努力调和,总是有些人会闹得不可开交。最后大圈子分化成多个小圈子,然后各自相安无事,然后小圈子扩大,又开始混乱,然后再分裂。这个过程我亲身经历,感受颇深。

和六度经常提起的还有一个150人原则,这个原则说从人的精力来看,很难管理超过150人的关系。其实我相信这里也是因为好友扁平化的保存在一度空间内过多,容易造成矛盾。150人原则从另一个层面说明我们的社会结构为什么会呈现树状体系或着说金子塔结构(树状和网状是观察点的区别,树可以看作网的特殊形式,网可以看作包含了树。),这是我一直想聊的一个问题,但是一直觉得想得还不够深入,所以这里就不细说了。

我们把友善关系当作正向,那么敌对关系就是负向。朋友的朋友是朋友的假设是一种幻想,同时和某人有正向关系的两个人的关系,很有可能是负向的,朋友关系是不能简单传递的。

文章已经很长了,但是我在这里没有想提出一种解决方案,只是跟大家聊聊我对六度的看法,希望对大家有启发,也希望大家的意见能给我启示,后面有时间也许会聊聊我对现有SNS服务的看法,最近总是很忙,呵呵。

原文: http://blog.donews.com/tinyfool/archive/2005/08/16/511891.aspx

posted @ 2006-09-03 23:47 hopeshared 阅读(287) | 评论 (0)编辑 收藏

六度理论传递的是什么?

目前国内SNS网站分为两种,一是交友,二是商务。

交友走的是大众路线,例如yeeyoo等;商务走的是专业路线,例如www.linkist.com等。

看到有很多的关于sns的评论文章,有赞扬,有批评。

批评者往往抓住六度理论中节点之间的系数问题做文章,应该说这些人对于sns有很好的了解,也有很好的认识。但是他们忽视了一点,就是六度理论节点与节点之间传递的是什么的问题。

在我的理解当中,SNS的节点与节点之间传递的是信任,是利益,而不是友谊。所谓的朋友的朋友是朋友,这个是错误的。在现实生活中,朋友的朋友通过介绍,相对于陌生人更容易建立起联系,这就是关系的哲学。但是,这个并不是友谊的直接传递,而是信任的传递,由信任而结成友谊。

通过网络,a认识b,b认识c,a与c之间建立起链接,这个要比a直接找c成功率大的多。人与人之间,信任、利益都可能成为朋友的充分必要条件,而这也是SNS网站存在的基础。

举个例子,还是abc,a认识b,b认识c,a想认识c,这中间有两个传递的力量:

a和b有很好的信任关系,b和c有很好的信任关系,那么a通过b认识c,这个信任是可以传递的;

a和b有利益关系,b和c有利益关系,a为了利益希望认识c,那么b是可以看到预期利益的,也就会帮助a认识c。


这两个力量的传递是存在组合关系的,因此,也就存在多种可能,并将其传递下去。网络的力量就在于包容一切的力量,在SNS的世界里,并不存在友谊的传递,但是存在信任和利益的传递。SNS的六度理论也是建立在这个的基础上,而不是友谊的基础。a是b的朋友,b是c的朋友,c是d的朋友,但d不一定和a能够成为朋友。

SNS的意义在于,通过这一个系统,你可以链接到你想认识的人。还是打个比方:

a想认识h,通过SNS他可以通过b认识h,也可以通过c-d认识h,也可以通过e-f-g认识h,有三个途径的选择,而途径的选择取决于两个因素,一是路径的距离,二是节点之间的链接系数。

无法否认的是,SNS的六度理论是建立在弱链接的基础上的,但由于存在信任和利益等影响因素,这个弱链接是可以传递的,并且有多种传递的可能性。

以上是看了笨狸《“关系”和SNS》http://blog.donews.com/banly/archive/2005/09/01/535403.aspx 之后的一些想法,与笨狸先生讨论。

原文:http://blog.donews.com/writerrr/archive/2005/09/01/536231.aspx

posted @ 2006-09-03 23:44 hopeshared 阅读(338) | 评论 (0)编辑 收藏

小时候听说洋鬼子来中国做生意会水土不服,因为他们不懂什么叫做“关系”。现在看到不少国人,居然学习着SNS,看来关于“关系”,鬼子不但已经懂,还开始让我们反过来去学。

一开始我以为“关系”是1.0,而SNS是2.0,很是敬佩,学了半天一度六度,发现SNS其实很肤浅,完全不如“关系”这种1.0的东西。

“关系”很简单,完全东方式,只可意会无法言传。一定要“定义”它的话,勉强可以说:

所谓关系,就是围绕某种利益目的而搭建的价值传递载体。

最多通过六个人,我可以认识拉登,也许,不过绝对是空话。相反,如果我能够提供百万个活体炸弹,拉登应该马上会来找我。这就是“关系”比SNS理论强的地方。

依稀记得,当年城里只要有了一张二十吨鸡爪的批文,这个信息传递到我这个不做批文的圈外人手里时,让我以为城里有了千万吨的鸡爪进口许可。每个人都说他有这个批文,都在找买家。在这个传递过程中,信息是不完整和不对称的,可能中间有人要了其中的10吨,想找另外一个买家来合作。所以,有人说他有5吨,有人说他有15吨。如果我把总量加起来,去兜售千万吨鸡爪的批文,到头来,会发现只剩下5吨的额度。传递链条中的每个人,为了保护自己的增量价值,都不可能直接把源头供出。我不知道SNS理论,如何定义这中间的变量。

当我曾经在云南看到很多某主席,某参谋长的纸条时,刚出校门的我很兴奋,觉得自己离中央真近。不过很快就发现,那些拿着纸条的人,其实很多也都没有和那个签名有过任何接触以及任何信息传递,他们也知道不可能,而且一般做完事情就结束掉,以后提都不提。

在国内,对于那些营造商业圈的SNS模式,我没有办法看好,因为缺乏明确的“某种利益目的”。至于做男女交友的,可以看好,因为利益目的很明晰,是性交网。按照这个推理,做商业应用的SNS,只能垂直,比如批文网,证监会网,煤矿网,运营商网等等。这种推论,只有在“关系”这个1.0理论的指导下才能完成。

SNS错误的地方,是犯了西方文明的老毛病,关注人本体,总是说节点。节点根本不重要,重要的是利益目的。比如笨狸这个本体一点用处都没有,只有当笨狸被任命为局长的时候,参与到利益目的中去了,才能进入“关系”,当笨狸退休或者被双规,那么一般来说,就在这个“关系”中消失,特例就不讨论了。

SNS是一个个节点和一条条线,所以编织成所谓的社会关系网络,这种僵硬呆板的理论实在不值得研究。而“关系”是动态的一个个圈,有了某个利益目的中心,就泛一个美丽而秘密的小涟漪,涟漪消失之后,一切都没有痕迹。

a通过b找到了c办成了一个事情,不证明c就是a的二度关系,没有关系。只有a-b,b-c这两个小涟漪浮动了一下。

“关系”是模糊数学,混沌理论范畴的,也是实用的。巩固原有关系也好,拓展交际圈也好,主要在于“围绕某种利益目的”,然后忽略掉分享增值价值的所有环节吧。找到利益维系的中心,比找到认识的人更为重要。所以结论是:每个人都是共同利益之下的一度好友。



cplwj 发表于2005-09-01 10:23 AM  IP: 219.82.107.*
从”六度交友”理论想到的

从今年春天开始的对Web2.0的叫嚣, 从Web2.0引发的对网络SNS交友网络的狂热, 我们想到了很多. 现在到了该坐下来冷静思考的时候了.

一, 老生常谈的”六度理论”更多的是个数学理论

关于”六度理论”, 最近在互联网上多有描述, 这里不再赘述. 本人认为, “六度理论”与其说是一个社会学理论或心理学理论, 还不如把它归类为一个以数学理论为主而略具社会学或心理学特征的理论. 说它更多的具有的是数学理论的特性, 因为根据“六度分隔法”(Six degrees of separation)事实上可以将世界上的所有人联系起来。事实上,如果网络中的每个人都能新结识100个朋友,那么他们每人将拥有100万个“三度朋友”;如果再增加“两度”的话,整个个人关系网络的人数将超过全球人口。难怪乎, 有人说, 我们可以通过”六度理论””结识”克林顿和比尔盖茨.

二. “弱联系”在SNS交友网络和现实生活中的区别.

“六度理论”中极力推崇的”弱联系”或称”弱连接”在人类人际交往中的作用. 我初次接触这一说法的时候曾经兴奋过一阵子, 认为SNS网络似乎真的在为我们提供一个快速便捷的社交平台. 后来一细想, 网络社交平台上的”弱连接”在互联网低成本高效率的背后无法真正达到”弱连接”本来应该具有的作用. 让我们回到现实社会,想一想这个弱连接是如何发挥作用. 比如我找到一个一度的朋友帮忙要解决某个问题, 一度朋友不能解决这个问题, 于是乎他便打电话给他的二度朋友, 二度朋友可能再向三度朋友传递, 结果问题在三度朋友手上给解决了. 其实我跟这个”三度”完全是有一种微弱的关系维系着的. 但是由于这种”微弱关系”有了一层接一层的”打电话”的”加固”, 使得现实生活中的我们频频受惠于这”微弱关系”. 但请记住, 现实生活中的加固”微弱关系”的”打电话”的过程, 其实其成本是很高的. 这就是中国人通常所说的”人情债”, 这个成本是无法以金钱计算的.

让我们再回到SNS网络里提到的”微弱关系”, 这个微弱关系似乎可以通过互联网的低成本优势得以”加固”, 但是实际上这种通过”搜索”朋友圈里的联系人的看似低成本的方法, 它根本无法实现现实生活中的加固微弱关系的作用, 它反而成了对朋友的骚扰. 所以任何想”低成本”的加固”微弱关系”的尝试最终将是徒劳的.

三. 六度关系中传递的什么?

六度理论中宣称我们可以通过”朋友的朋友”认识可靠的朋友. 这个理论听起来似乎没错. 20 世纪60年代,耶鲁大学的社会心理学家米尔格兰姆(Stanley Milgram)就设计了一个连锁信件实验。他将一套连锁信件随机发送给居住在内布拉斯加州奥马哈的160个人,信中放了一个波士顿股票经纪人的名字,信中要求每个收信人将这套信寄给自己认为是比较接近那个股票经纪人的朋友。朋友收信后照此办理。最终,大部分信在经过五、六个步骤后都抵达了该股票经纪人。六度理论(也叫“六度空间””六度分割”)的概念由此而来。这个故事很多六度的爱好者都知道,并奉为圣经。但是我请大家注意这个故事和我们现在流行的SNS网站的理念的重要区别。在这个故事里面,信到达了波士顿股票经纪人手里面没错,但是请注意整个过程中,每个人的朋友关系都没有发生改变。这个故事里面传递的信息,而我们现在看到的SNS网站希望在用户之间传递的是什么呢?是联系方式是朋友关系。但这个试验中传递的实际上是信息而已,而不是朋友关系。这也就是我们通过六度理论可以把”信息”传递给克林顿, 而无法打电话给老克一起共进早餐的原因.通过”六度”是无法传递”友情”的. 友谊和友情是有限的人群在亲密和共识的基础上建立起来的。一个真正的社交网络狭小而封闭:它是一个由栏杆围起的社区,而不是一个向地平线延伸的大都市。

四. 150人原则

上面提到的有限的人群的基础上的朋友感情, 实际上是个很狭小的空间. 这就是和六度理论一起经常提起的”150人原则”,这个原则说从人的精力来看,很难管理超过150人的关系. 而我们从小学开始成为一个社会人开始, 大都经历小学, 初中,高中和大学, 然后进入社会从事各类工作. 这么一个过程, 一个人能结识的比较”一度”的朋友也就150个人.当然这个数字随个人的性格而有差异.

五. 对”150人”关系管理的缺失

我们都承认我们有这”150人”的一度关系的存在.但是现实的现状是, 我们没有一个人把这个150人的一度关系管理好. 以一个刚刚走入工作岗位的人为例, 我们经历了各个学习阶段, 试问自己, 我们还有几个人还知道几个小学同学的联系方式? 几个初中同学的联系方式? 几个高中同学的联系方式? 再过五六年, 还有几个人还能随时联系得上大学的同学? 这里有必要提醒大家, 同学友谊是世间最纯洁的友谊之一, 它不带有任何功利的因素. 其实我们的同学, 以及以后认识的同事朋友分布在各行各业, 密切的维护这些关系对我们的事业和生活都已足够. 而在SNS叫嚣下的中国, 似乎只有二度三度甚至五度六度的朋友才是事业成功的基石. 我们在此是大错了. 新近的 www.LL51.com ”联络无忧”通讯录倒是为我们解决了这个问题. 这是一个简单的通讯录工具, 是个互动的工具, 我们不妨可以冠之以”AddressBook2.0”, 这是一个维护”150人”一度朋友的工具. 每个人的联系方式有很多, 你在充分消除你对”隐私”的忧虑之后, 你只要留给你的一度朋友一个或多个能够随时找到你的联系方式, 如现在经常使用邮址, 如手机号码, 如QQ, 如MSN等等, 这样我们就不会间断和朋友的联系了!

罗里罗嗦写多了. 不妨让我们从叫嚣一阵子了的”六度理论”中走出来, 回到现实中去. 社交网络让我们一下子拥有几千个几万个几十万个“朋友”短时间内还感觉挺有趣的,但这种快乐最终将逐渐消失。更重要的是, 让我们管好眼前的朋友, 不要让培养多年的同学友情, 同事友情在岁月无情的涤荡中消失在我们的视野.

lucy@linkist 发表于2005-09-01 10:40 AM  IP: 218.1.194.*
呵呵,果然是刚出校门不久的社会人 :) 如果你将来走的是从政之路,那么这篇文章非常有道理,SNS对政客确实也没什么用。如果不小心走了国际化的商业之路,我是不太相信你过10年还象今天这么想。
“a通过b找到了c办成了一个事情,不证明c就是a的二度关系,没有关系。只有a-b,b-c这两个小涟漪浮动了一下。”
是不是二度关系并不重要,SNS的精髓也不在于确定a和c之间到底应该是几度。没有SNS,a为了找到c,只能一个个电话去询问所有的朋友,最后也许碰巧发现c能办事;而有了SNS,a一下就可以找到c了。至于c帮不帮,那是互联网外的事情了。
前两天有个朋友拜托我找人帮他递个简历给Cisco(听说Cisco对无介绍人的简历几乎不看,也从来不委托猎头招聘),没有SNS的话,也许花一年都找不到引荐人…… 你认为还可以用什么方法很快地寻找到介绍人呢?


原文:http://blog.donews.com/banly/archive/2005/09/01/535403.aspx


posted @ 2006-09-03 23:42 hopeshared 阅读(966) | 评论 (0)编辑 收藏

by Hao He
August 11, 2004

Despite the lack of vendor support, Representational State Transfer (REST) web services have won the hearts of many working developers. For example, Amazon's web services have both SOAP and REST interfaces, and 85% of the usage is on the REST interface. Compared with other styles of web services, REST is easy to implement and has many highly desirable architectural properties: scalability, performance, security, reliability, and extensibility. Those characteristics fit nicely with the modern business environment, which commands technical solutions just as adoptive and agile as the business itself.

A few short years ago, REST had a much lower profile than XML-RPC, which was much in fashion. Now XML-RPC seems to have less mindshare. People have made significant efforts to RESTize SOAP and WSDL. The question is no longer whether to REST, but instead it's become how to be the best REST?

The purpose of this article is to summarize some best practices and guidelines for implementing RESTful web services. I also propose a number of informal standards in the hope that REST implementations can become more consistent and interoperable.

The following notations are used in this article:

  1. BP: best practice
  2. G: general guideline
  3. PS: proposed informal standard
  4. TIP: implementation tip
  5. AR: arguably RESTful -- may not be RESTful in the strict sense

Reprising REST

Let's briefly reiterate the REST web services architecture. REST web services architecture conforms to the W3C's Web Architecture, and leverages the architectural principles of the Web, building its strength on the proven infrastructure of the Web. It utilizes the semantics of HTTP whenever possible and most of the principles, constraints, and best practices published by the TAG also apply.

The REST web services architecture is related to the Service Oriented Architecture. This limits the interface to HTTP with the four well-defined verbs: GET, POST, PUT, and DELETE. REST web services also tend to use XML as the main messaging format.

[G] Implementing REST correctly requires a resource-oriented view of the world instead of the object-oriented views many developers are familiar with.

Resource

One of the most important concepts of web architecture is a "resource." A resource is an abstract thing identified by a URI. A REST service is a resource. A service provider is an implementation of a service.

URI Opacity [BP]

The creator of a URI decides the encoding of the URI, and users should not derive metadata from the URI itself. URI opacity only applies to the path of a URI. The query string and fragment have special meaning that can be understood by users. There must be a shared vocabulary between a service and its consumers.

Query String Extensibility [BP, AR]

A service provider should ignore any query parameters it does not understand during processing. If it needs to consume other services, it should pass all ignored parameters along. This practice allows new functionality to be added without breaking existing services.

[TIP] XML Schema provides a good framework for defining simple types, which can be used for validating query parameters.

Deliver Correct Resource Representation [G]

A resource may have more than one representation. There are four frequently used ways of delivering the correct resource representation to consumers:

  1. Server-driven negotiation. The service provider determines the right representation from prior knowledge of its clients or uses the information provided in HTTP headers like Accept, Accept-Charset, Accept-Encoding, Accept-Language, and User-Agent. The drawback of this approach is that the server may not have the best knowledge about what a client really wants.
  2. Client-driven negotiation. A client initiates a request to a server. The server returns a list of available of representations. The client then selects the representation it wants and sends a second request to the server. The drawback is that a client needs to send two requests.
  3. Proxy-driven negotiation. A client initiates a request to a server through a proxy. The proxy passes the request to the server and obtains a list of representations. The proxy selects one representation according to preferences set by the client and returns the representation back to the client.
  4. URI-specified representation. A client specifies the representation it wants in the URI query string.

Server-Driven Negotiation [BP]

  1. When delivering a representation to its client, a server MUST check the following HTTP headers: Accept, Accept-Charset, Accept-Encoding, Accept-Language, and User-Agent to ensure the representation it sends satisfies the user agent's capability.
  2. When consuming a service, a client should set the value of the following HTTP headers: Accept, Accept-Charset, Accept-Encoding, Accept-Language, and User-Agent. It should be specific about the type of representation it wants and avoid "*/*", unless the intention is to retrieve a list of all possible representations.
  3. A server may determine the type of representation to send from the profile information of the client.

URI-Specified Representation [PS, AR]

A client can specify the representation using the following query string:

mimeType={mime-type}

A REST server should support this query.

Different Views of a Resource [PS, AR]

A resource may have different views, even if there is only one representation available. For example, a resource has an XML representation but different clients may only see different portion of the same XML. Another common example is that a client might want to obtain metadata of the current representation.

To obtain a different view, a client can set a "view" parameter in the URI query string. For example:


GET http://www.example.com/abc?view=meta

where the value of the "view" parameter determines the actual view. Although the value of "view" is application specific in most cases, this guideline reserves the following words:

  1. "meta," for obtaining the metadata view of the resource or representation.
  2. "status," for obtaining the status of a request/transaction resource.

Service

A service represents a specialized business function. A service is safe if it does not incur any obligations from its invoking client, even if this service may cause a change of state on the server side. A service is obligated if the client is held responsible for the change of states on server side.

Safe Service

A safe service should be invoked by the GET method of HTTP. Parameters needed to invoke the service can be embedded in the query string of a URI. The main purpose of a safe service is to obtain a representation of a resource.

Service Provider Responsibility [BP]

If there is more than one representation available for a resource, the service should negotiate with the client as discussed above. When returning a representation, a service provider should set the HTTP headers that relate to caching policies for better performance.

A safe service is by its nature idempotent. A service provider should not break this constraint. Clients should expect to receive consistent representations.

Obligated Services [BP]

Obligated services should be implemented using POST. A request to an obligated service should be described by some kind of XML instance, which should be constrained by a schema. The schema should be written in W3C XML Schema or Relax NG. An obligated service should be made idempotent so that if a client is unsure about the state of its request, it can send it again. This allows low-cost error recovery. An obligated service usually has the simple semantic of "process this" and has two potential impacts: either the creation of new resources or the creation of a new representation of a resource.

Asynchronous Services

One often hears the criticism that HTTP is synchronous, while many services need to be asynchronous. It is actually quite easy to implement an asynchronous REST service. An asynchronous service needs to perform the following:

  1. Return a receipt immediately upon receiving a request.
  2. Validate the request.
  3. If the request if valid, the service must act on the request as soon as possible. It must report an error if the service cannot process the request after a period of time defined in the service contract.

Request Receipt

An example receipt is shown below:

<receipt xmlns="http://www.xml.org/2004/rest/receipt" requestUri = "http://www.example.com/xya343343" received = "2004-10-03T12:34:33+10:00">
  <transaction uri="http://www.example.com/xyz2343" status = "http://www.example.com/xyz2343?view=status"/>
</receipt>

A receipt is a confirmation that the server has received a request from a client and promises to act on the request as soon as possible. The receipt element should include a received attribute, the value of which is the time the server received the request in WXS dateTime type format. The requestUri attribute is optional. A service may optionally create a request resource identified by the requestUri. The request resource has a representation, which is equivalent to the request content the server receives. A client may use this URI to inspect the actual request content as received by the server. Both client and server may use this URI for future reference.

However, this is application-specific. A request may initiate more than one transaction. Each transaction element must have a URI attribute which identifies this transaction. A server should also create a transaction resource identified by the URI value. The transaction element must have a status attribute whose value is a URI pointing to a status resource. The status resource must have an XML representation, which indicates the status of the transaction.

Transaction

A transaction represents an atomic unit of work done by a server. The goal of a transaction is to complete the work successfully or return to the original state if an error occurs. For example, a transaction in a purchase order service should either place the order successfully or not place the order at all, in which case the client incurs no obligation.

Status URI [BP, AR]

The status resource can be seen as a different view of its associated transaction resource. The status URI should only differ in the query string with an additional status parameter. For example:

Transaction URI: http://www.example.com/xyz2343 Transaction Status URI: http://www.example.com/xyz2343?view=status

Transaction Lifecycle [G]

A transaction request submitted to a service will experience the following lifecycle as defined in Web Service Management: Service Life Cycle:

  1. Start -- the transaction is created. This is triggered by the arrival of a request.
  2. Received -- the transaction has been received. This status is reached when a request is persisted and the server is committed to fulfill the request.
  3. Processing -- the transaction is being processed, that is, the server has committed resources to process the request.
  4. Processed -- processing is successfully finished. This status is reached when all processing has completed without any errors.
  5. Failed -- processing is terminated due to errors. The error is usually caused by invalid submission. A client may rectify its submission and resubmit. If the error is caused by system faults, logging messages should be included. An error can also be caused by internal server malfunction.
  6. Final -- the request and its associated resources may be removed from the server. An implementation may choose not to remove those resources. This state is triggered when all results are persisted correctly.

Note that it is implementation-dependent as to what operations must be performed on the request itself in order to transition it from one status to another. The state diagram of a request (taken from Web Service Management: Service Life Cycle) is shown below:

The state diagram of a request (taken from Web Service Management: Service Life Cycle)

As an example of the status XML, when a request is just received:

<status state="received" timestamp="2004-10-03T12:34:33+10:00" />

The XML contains a state attribute, which indicates the current state of the request. Other possible values of the state attribute are processing, processed, and failed.

When a request is processed, the status XML is (non-normative):

<status state="processed" timestamp="2004-10-03T12:34:33+10:00" >
  <result uri="http://example.com/rest/1123/xyz" />
</status>

This time, a result element is included and it points to a URL where the client can GET request results.

In case a request fails, the status XML is (non-normative):


<status   state="failed" timestamp="2002-10-03T12:34:33+10:00" >
  <error code="3" >
    <message>A bad request. </message>
    <exception>line 3234</exception>
  </error>
</status>

A client application can display the message enclosed within the message tag. It should ignore all other information. If a client believes that the error was not caused by its fault, this XML may serve as a proof. All other information is for internal debugging purposes.

Request Result [BP]

A request result view should be regarded as a special view of a transaction. One may create a request resource and transaction resources whenever a request is received. The result should use XML markup that is as closely related to the original request markup as possible.

Receiving and Sending XML [BP]

When receiving and sending XML, one should follow the principle of "strict out and loose in." When sending XML, one must ensure it is validated against the relevant schema. When receiving an XML document, one should only validate the XML against the smallest set of schema that is really needed. Any software agent must not change XML it does not understand.

An Implementation Architecture

An Implementation Architecture

The architecture represented above has a pipe-and-filter style, a classical and robust architectural style used as early as in 1944 by the famous physicist, Richard Feynman, to build the first atomic bomb in his computing team. A request is processed by a chain of filters and each filter is responsible for a well-defined unit of work. Those filters are further classified as two distinct groups: front-end and back-end. Front-end filters are responsible to handle common Web service tasks and they must be light weight. Before or at the end of front-end filters, a response is returned to the invoking client.

All front-end filters must be lightweight and must not cause serious resource drain on the host. A common filter is a bouncer filter, which checks the eligibility of the request using some simple techniques:

  1. IP filtering. Only requests from eligible IPs are allowed.
  2. URL mapping. Only certain URL patterns are allowed.
  3. Time-based filtering. A client can only send a certain number of requests per second.
  4. Cookie-based filtering. A client must have a cookie to be able to access this service.
  5. Duplication-detection filter. This filter checks the content of a request and determines whether it has received it before. A simple technique is based on the hash value of the received message. However, a more sophisticated technique involves normalizing the contents using an application-specific algorithm.

A connector, whose purpose is to decouple the time dependency between front-end filters and back-end filters, connects front-end filters and back-end filters. If back-end processing is lightweight, the connector serves mainly as a delegator, which delegates requests to its corresponding back-end processors. If back-end processing is heavy, the connector is normally implemented as a queue.

Back-end filters are usually more application specific or heavy. They should not respond directly to requests but create or update resources.

This architecture is known to have many good properties, as observed by Feynman, whose team improved its productivity many times over. Most notably, the filters can be considered as a standard form of computing and new filters can be added or extended from existing ones easily. This architecture has good user-perceived performance because responses are returned as soon as possible once a request becomes fully processed by lightweight filters. This architecture also has good security and stability because security breakage and errors can only propagate a limited number of filters. However, it is important to note that one must not put a heavyweight filter in the front-end or the system may become vulnerable to denial-of-service attacks.

posted @ 2006-08-31 17:26 hopeshared 阅读(788) | 评论 (0)编辑 收藏

I am seeing a lot of new web services are implemented using a REST style architecture these days rather than a SOAP one. Lets step back a second and explain what REST is.

What is a REST Web Service

The acronym REST stands for Representational State Transfer, this basically means that each unique URL is a representation of some object. You can get the contents of that object using an HTTP GET, to delete it, you then might use a POST, PUT, or DELETE to modify the object (in practice most of the services use a POST for this).

Who's using REST?

All of Yahoo's web services use REST, including Flickr, del.icio.us API uses it, pubsub, bloglines, technorati, and both eBay, and Amazon have web services for both REST and SOAP.

Who's using SOAP?

Google seams to be consistent in implementing their web services to use SOAP, with the exception of Blogger, which uses XML-RPC. You will find SOAP web services in lots of enterprise software as well.

REST vs SOAP

As you may have noticed the companies I mentioned that are using REST api's haven't been around for very long, and their apis came out this year mostly. So REST is definitely the trendy way to create a web service, if creating web services could ever be trendy (lets face it you use soap to wash, and you rest when your tired). The main advantages of REST web services are:

  • Lightweight - not a lot of extra xml markup
  • Human Readable Results
  • Easy to build - no toolkits required

SOAP also has some advantages:

  • Easy to consume - sometimes
  • Rigid - type checking, adheres to a contract
  • Development tools

For consuming web services, its sometimes a toss up between which is easier. For instance Google's AdWords web service is really hard to consume (in CF anyways), it uses SOAP headers, and a number of other things that make it kind of difficult. On the converse, Amazon's REST web service can sometimes be tricky to parse because it can be highly nested, and the result schema can vary quite a bit based on what you search for.

Which ever architecture you choose make sure its easy for developers to access it, and well documented.




原文:http://www.petefreitag.com/item/431.cfm

posted @ 2006-08-31 17:21 hopeshared 阅读(1293) | 评论 (0)编辑 收藏

仅列出标题
共30页: First 上一页 4 5 6 7 8 9 10 11 12 下一页 Last