Programmieraufgabe CN 03/04 Pascal Zumkehr, Matthias Stürmer

Remote Procedure Call (RPC)

What is RPC

RPC is a powerful technique for constructing distributed, client-server based applications. It is based on extending the notion of conventional, or local procedure calling, so that the called procedure need not exist in the same address space as the calling procedure. The two processes may be on the same system, or they may be on different systems with a network connecting them. By using RPC, programmers of distributed applications avoid the details of the interface with the network. The transport independence of RPC isolates the application from the physical and logical elements of the data communications mechanism and allows the application to use a variety of transports.

How RPC Works

An RPC is analogous to a function call. Like a function call, when an RPC is made, the calling arguments are passed to the remote procedure and the caller waits for a response to be returned from the remote procedure. The following image shows the flow of activity that takes place during an RPC call between two networked systems. The client makes a procedure call that sends a request to the server and waits. The thread is blocked from processing until either a reply is received, or it times out. When the request arrives, the server calls a dispatch routine that performs the requested service, and sends the reply to the client. After the RPC call is completed, the client program continues.

A remote procedure is uniquely identified by the triple: (program number, version number, procedure number) The program number identifies a group of related remote procedures, each of which has a unique procedure number. A program may consist of one or more versions. Each version consists of a collection of procedures which are available to be called remotely. Version numbers enable multiple versions of an RPC protocol to be available simultaneously. Each version contains a a number of procedures that can be called remotely. Each procedure has a procedure number.

Remote Procedure Calls are high-level communications mechanisms. RPC presumes the existence of low-level networking mechanisms (such as TCP/IP and UDP/IP), and implements on them a logical client-to-server communications system designed specifically for the support of network applications. With RPC, the client makes a procedure call to send a data packet to the server. When the packet arrives, the server calls a dispatch routine, performs whatever service is requested, sends back the reply, and returns the procedure call to the client.

7. Februar 2004 Seite 1 von 4 Programmieraufgabe CN 03/04 Pascal Zumkehr, Matthias Stürmer

Layers of RPC

The RPC interface can be seen as being divided into three layers.

The Highest Layer

The highest layer is totally transparent to the , machine, and network on which it is run. Think of this level as a way of using RPC, rather than as a part of RPC itself.

The Middle Layer

The middle layer is really the heart of RPC. Here, the user does not need to consider details about sockets, the system, or other low-level implementation mechanisms. They simply make remote procedure calls to routines on other machines. The inherent value of this layer is its simplicity. It is this layer that allows RPC to pass the "hello world" test.

The middle layer is rarely used in serious programming due to its simplicity. It does not allow timeout specifications or the choice of transport. It allows no UNIX process control or flexibility in case of errors. It does not support multiple types of call authentication. You rarely need all these types of control, but one or two of them is often necessary.

The Lowest Layer

The lowest layer lets you control these details, and for that reason it is often necessary. Programs written at this level are also most efficient, but this is usually not an issue, since RPC clients and servers rarely generate heavy network loads.

The RPC Paradigm

Here is a diagram of the RPC paradigm:

1. RPC client program issues an RPC call to a remote procedure.

2. RPC forwarder recognizes call to a mainframe service and forwards RPC call over the channel.

3. Mainframe RPC server accepts the call and forwards the request to the RPC application.

Implementation and Syntax of XML-RPC

As described before, the only things needed to send or process a remote procedure call are an HTTP processor and the XML file with the corresponding structures. In this section, the syntax of the HTTP Header and the XML file are going to be presented. An XML-RPC message is an HTTP-POST request with a common HTTP Header and an XML body. The reply given after processing by the server is also in XML format.

7. Februar 2004 Seite 2 von 4 Programmieraufgabe CN 03/04 Pascal Zumkehr, Matthias Stürmer

HTTP Header Request

POST /RPC2 HTTP/1.0 User-Agent: Frontier/5.1.2 (WinNT) Host: betty.userland.com Content-Type: text/xml Content-length: 181

The first line of the HTTP header tells the server that the type of the request is HTTP POST and also specifies the URI for the server. It can be empty or just a single slash for a server that just handles RPC requests, but usually, if other HTTP requests are processed, the URI helps the server to route the XML-RPC request to the handling code. In this example the server is told to route the request to the RPC2 responder, as it is done for the Google XML-RPC handler provided by xmlrpc.com. A User-Agent and a Host have to be specified to guarantee a correct handling of the request. The same is true for the Content-length (without the header), which also has to be correct.

XML Body Request

googleGateway.spellingSuggestion Helo World 1234567890

The structure of the XML is quite simple. There is only one main structure, called , and can contain two different sub-items: The tag, which is mandatory, holding a string that specifies the name of the method to be called. It is entirely up to the server how this string is interpreted. So the methodName could be a file containing a script to execute or, like in this example, a path to find the method. The other sub-item is the tag, which can contain any number of tags, one for each parameter the method requests. If the method doesn’t take any parameters at all, the tag doesn’t need to be specified. Each tag contains a , where the data type and the actual value are indicated. Allowed data types are , , , , , , the default type is . Furthermore, it is also possible to pass structures and arrays, which are both recursive, i.e. A can contain another in a . The syntax for a structure is [name value], for an array it’s [value], it is allowed to mix the types in an array.

Reply

The response by the server looks quite similar. The first line of the HTTP Header contains always “HTTP/1.1 200 OK”, unless there is a lower-level error. The content type must be set to text/xml again, and also the content-length must be specified and correct. The important part is the XML body of the reply: The main structure is a that can contain a single that contains a single , which contains a single . In the case of an error, can also contain a tag, which contains a

7. Februar 2004 Seite 3 von 4 Programmieraufgabe CN 03/04 Pascal Zumkehr, Matthias Stürmer

which is a having two s, one named faultCode, an and one named faultString, a containing more information on the error. A cannot contain both a and a tag.

Hello World

Sources http://www.cisco.com/univercd/cc/td/doc/product/software/ioss390/ios390rp/rprdesc.htm http://www.xmlrpc.com http://ws.apache.org/xmlrpc/

Test Questions

1. What are the main advantages of RPC? 2. What are the six main steps of a RPC Call and who is doing them? 3. How many layers has the RPC interface and what are they called? 4. Name three different valid data type tags for XML-RPC 5. Do the elements of an array in XML-RPC have to be from the same data type?

Answers

1. By using RPC, programmers of distributed applications avoid the details of the interface with the network. The transport independence of RPC isolates the application from the physical and logical elements of the data communications mechanism and allows the application to use a variety of transports. 2. Client: 1. callrpc function Server: 2. execute request 3. call service 4. executes service 5. request completes, return reply Client: 6. program continues 3. Three: The Highest Layer, the Middle Layer and the Lowest Layer 4. , , , , , 5. No, as the data type is indicated separately in each tag.

7. Februar 2004 Seite 4 von 4