XML-RPC实现学习笔记

[The definition of XML-RPC]
  An XML-RPC message is an HTTP-POST request. The body of the request is in XML. A procedure executes on the server and the value it returns is also formatted in XML.
XML-RPC是一个Http-Post请求,请求的boy是一个XML, 一个执行在server 上的方法,当然执行之后返回的值也是用的XML.

[Request Sample]
Here's an example of an XML-RPC request:
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>

一般来说,服务端可能会处理很多HttpRequest请求,但是如何区分出这个请求是RPC请求呢?主要是根据HttpRequest头部的/RPC2来区分的。
A User-Agent and Host must be specified.
The Content-Type is text/xml.
The Content-Length must be specified and must be correct.

[Response example]
Here's an example of a response to an XML-RPC request:

HTTP/1.1 200 OK
Connection: close
Content-Length: 158
Content-Type: text/xml
Date: Fri, 17 Jul 1998 19:55:08 GMT
Server: UserLand Frontier/5.1.2-WinNT


<?xml version="1.0"?>
<methodResponse>
   <params>
      <param>
         <value><string>South Dakota</string></value>
         </param>
      </params>
   </methodResponse>


[Fault example]

TP/1.1 200 OK
Connection: close
Content-Length: 426
Content-Type: text/xml
Date: Fri, 17 Jul 1998 19:55:02 GMT
Server: UserLand Frontier/5.1.2-WinNT


<?xml version="1.0"?>
<methodResponse>
   <fault>
      <value>
         <struct>
            <member>
               <name>faultCode</name>
               <value><int>4</int></value>
               </member>
            <member>
               <name>faultString</name>
               <value><string>Too many parameters.</string></value>
               </member>
            </struct>
         </value>
      </fault>
   </methodResponse>


[The structor of RPC-XML body]

Request:
<methodCall>
  <params>
<param>
  <value>详看下表<value>
<param>
....多个<param>节点
  </params>
</methodCall>


Response:

<methodResponse>
  <params>
<param>
  <value>....</value>
</param>
	 .........多个<param>节点
  </params>
</methodResponse>


Fault:

<methodResponse>
  <fault>
  <struct>
  <member>
    <mame>faultcode</name>
    <value>…………</value>
  </member>
  <member>
    <mame>faultstring</name>
    <value>…………</value>
  </member>
  <member>
    <mame>faultactor</name>
    <value>…………</value>
  </member>
  <member>
    <mame>detail</name>
    <value>…………</value>
  </member>
</struct>
  </fault>
</methodResponse>



[RPC Scalar Value Type]

Tag                     Type                      Example
<i4> or <int> four-byte signed integer             -12
<boolean> 0 (false) or 1 (true)             1
<string>                    string                    hello world
<double>   double-precision signed floating point number  -12.214
<dateTime.iso8601>         date/time                19980717T14:08:55
<base64>          base64-encoded binary   eW91IGNhbid0IHJlYWQgdGhpcyE=


If no type is indicated, the type is string.

[Struct]

<struct>
   <member>
      <name>lowerBound</name>
      <value><i4>18</i4></value>
      </member>
   <member>
      <name>upperBound</name>
      <value><i4>139</i4></value>
    </member>
</struct>


any <value> may contain a <struct> or any other type, including an <array>.

[Array]

<array>
   <data>
      <value><i4>12</i4></value>
      <value><string>Egypt</string></value>
      <value><boolean>0</boolean></value>
      <value><i4>-31</i4></value>
      </data>
   </array>


<array> elements do not have names.
You can mix types as the example above illustrates.
<arrays>s can be recursive, any value may contain an <array> or any other type, including a <struct>





你可能感兴趣的:(java,xml)