JSON-RPC、XML-RPC、SOAP三者的关系
2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
JSON-RPC規(guī)范:http://json-rpc.org/wiki/specification
XML-RPC規(guī)范:http://www.xmlrpc.com/spec
SOAP規(guī)范:http://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383487
參考:http://weblog.masukomi.org/writings/xml-rpc_vs_soap.htm
三者都是為了實(shí)現(xiàn)RPC中的消息交換,并且都沒有定義傳輸協(xié)議。不過為了更方便在網(wǎng)絡(luò)中傳輸,而且由于HTTP的無狀態(tài)性,都使得HTTP為這三者的常用的傳輸協(xié)議。下面例子也是基于HTTP協(xié)議的
XML-RPC和SOAP都是基于XML格式的消息交換:
XML-RPC非常簡單,定義了幾種基本類型、匿名結(jié)構(gòu)體、匿名數(shù)組;
SOAP除了基本類型、命名結(jié)構(gòu)體、命名數(shù)組以外,還可以自定義類型,能使用多態(tài)的方法調(diào)用方式
而JSON-RPC是基于JSON格式的消息交換,JSON比XML更加輕巧,并且非常容易在頁面JS中使用,其他特點(diǎn)與XML-RPC類似
?
下面是使用這幾種協(xié)議發(fā)送請求的例子:
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>JSON-RPC
--> { "method": "echo", "params": ["Hello JSON-RPC"], "id": 1} <-- { "result": "Hello JSON-RPC", "error": null, "id": 1}?
實(shí)際上,以上實(shí)現(xiàn)正在退出歷史的舞臺,轉(zhuǎn)而會用restful風(fēng)格的web服務(wù)越來越多。
轉(zhuǎn)載于:https://my.oschina.net/ososchina/blog/856996
總結(jié)
以上是生活随笔為你收集整理的JSON-RPC、XML-RPC、SOAP三者的关系的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【PHP】PHPExcel类 excel
- 下一篇: .NET调用Oracle存储过程,使用数