JSON-RPC、XML-RPC、SOAP三者的关系
来源:互联网 发布:数控车削编程简单案例 编辑:程序博客网 时间:2024/06/06 13:21
JSON-RPC规范:http://json-rpc.org/wiki/specification
XML-RPC规范:http://www.xmlrpc.com/spec
SOAP规范:http://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383487
参考:http://weblog.masukomi.org/writings/xml-rpc_vs_soap.htm
三者都是为了实现RPC中的消息交换,并且都没有定义传输协议。不过为了更方便在网络中传输,而且由于HTTP的无状态性,都使得HTTP为这三者的常用的传输协议。下面例子也是基于HTTP协议的
XML-RPC和SOAP都是基于XML格式的消息交换:
XML-RPC非常简单,定义了几种基本类型、匿名结构体、匿名数组;
SOAP除了基本类型、命名结构体、命名数组以外,还可以自定义类型,能使用多态的方法调用方式
而JSON-RPC是基于JSON格式的消息交换,JSON比XML更加轻巧,并且非常容易在页面JS中使用,其他特点与XML-RPC类似
下面是使用这几种协议发送请求的例子:
XML-RPC
- POST /RPC2 HTTP/1.0
- User-Agent: Frontier/5.1.2 (WinNT)
- Host: betty.userland.com
- Content-Type: text/xml
- Content-length: 181
- <?xml version="1.0"?>
- <methodCall>
- <methodName>examples.getStateName</methodName>
- <params>
- <param>
- <value><i4>41</i4></value>
- </param>
- </params>
- </methodCall>
SOAP:
- POST /StockQuote HTTP/1.1
- Host: www.stockquoteserver.com
- Content-Type: text/xml; charset="utf-8"
- Content-Length: nnnn
- SOAPAction: "Some-URI"
- <SOAP-ENV:Envelope
- xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
- SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
- <SOAP-ENV:Header>
- <t:Transaction
- xmlns:t="some-URI"
- SOAP-ENV:mustUnderstand="1">
- 5
- </t:Transaction>
- </SOAP-ENV:Header>
- <SOAP-ENV:Body>
- <m:GetLastTradePrice xmlns:m="Some-URI">
- <symbol>DEF</symbol>
- </m:GetLastTradePrice>
- </SOAP-ENV:Body>
- </SOAP-ENV:Envelope>
JSON:
- --> { "method": "echo", "params": ["Hello JSON-RPC"], "id": 1}
- <-- { "result": "Hello JSON-RPC", "error": null, "id": 1}
转正 http://kingquake21.iteye.com/blog/1033471
REST以原始的http协议来传送信息。它属于RESTfull的范畴。
以GET或POST传送(废话),适用于传送简单的request信息。
以XML形式返回(response)。
开发时服务器端可以和一般的Web网站一样构建,客户端只要有解析HTTP和XML的DOM API即可。
采用RESTfull最有名的应该算是Twitter.com。
REST开发起来比较容易。
request
GET /WebSite1/WebService.asmx/getHello?str=string HTTP/1.1
Host: localhost
response
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">string</string>
SOAP以POST传送XML数据,适用于大量数据传送。
他也是以XML形式返回(response)。
开发时最好有中间件来协助。
request
POST /WebSite1/WebService.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/getHello"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
</soap:Envelope>
response
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
</soap:Envelope>
JSON基本上跟REST一样,不过response值不是XML格式的而是JSON格式
转自http://blog.sina.com.cn/s/blog_5e4a47dd0100go6f.html
- JSON-RPC、XML-RPC、SOAP三者的关系
- JSON-RPC、XML-RPC、SOAP三者的关系
- JSON-RPC,XML-RPC,SOAP
- RPC, SOAP, WSDL的关系
- XML-RPC, SOAP 的区别
- RMI/XML-RPC/JSON-RPC/SOAP概念比较
- RMI/XML-RPC/JSON-RPC/SOAP概念比较
- RMI/XML-RPC/JSON-RPC/SOAP概念比较
- XML-RPC & SOAP
- SOAP vs XML-RPC
- SOAP协议 XML-RPC
- XML-RPC、SOAP对比
- RPC、SOAP、WSDL之间的关系
- REST SOAP 和 XML-RPC
- xml-rpc和soap区别
- 三种主流的WebService实现方案(REST/SOAP/XML-RPC)简述及比较
- 三种主流的Web服务实现方案(REST+SOAP+XML-RPC)简述及比较
- 三种主流的Web服务实现方案(REST+SOAP+XML-RPC)简述及比较
- 递归小应用 .
- Linux 下 gethostbyname 简明用法
- JAVA集合类(介绍)
- 创建临时文件的简单方法 .
- 结构体对齐
- JSON-RPC、XML-RPC、SOAP三者的关系
- libcurl使用心得
- Android的垃圾回收机制(android refbase类(sp wp))
- 移动重定向
- SQL Server 2000 + 2005 + 2008 + 2008R2,完全可以共存,注意区别连接字符串写法
- 11月2日 导入包
- Linux下LibCurl编程转
- 套接字的地址结构
- dm9000.mini2440,2.6.32内核移植(修正版)