JSON-RPC、XML-RPC、SOAP三者的关系
2019獨角獸企業重金招聘Python工程師標準>>>
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>JSON-RPC
--> { "method": "echo", "params": ["Hello JSON-RPC"], "id": 1} <-- { "result": "Hello JSON-RPC", "error": null, "id": 1}?
實際上,以上實現正在退出歷史的舞臺,轉而會用restful風格的web服務越來越多。
轉載于:https://my.oschina.net/ososchina/blog/856996
總結
以上是生活随笔為你收集整理的JSON-RPC、XML-RPC、SOAP三者的关系的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【PHP】PHPExcel类 excel
- 下一篇: asp.net ajax控件工具集 Au