1 / 44

CIS017-6 - Distributed and Parallel Architectures

XML-RPC – Introduction. CIS017-6 - Distributed and Parallel Architectures. What is XML-RPC?. XML-RPC.com Simple cross-platform distributed computing, based on the standards of the Internet. See: http://xmlrpc.scripting.com/. What is XML-RPC?.

vpena
Download Presentation

CIS017-6 - Distributed and Parallel Architectures

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. XML-RPC – Introduction CIS017-6 - Distributed and Parallel Architectures

  2. What is XML-RPC? XML-RPC.comSimple cross-platform distributed computing, based on the standards of the Internet. See: http://xmlrpc.scripting.com/

  3. What is XML-RPC? It's a spec and a set of implementations that allow software running on disparate operating systems, running in different environments to make procedure calls over the Internet. It's remote procedure calling using HTTP as the transport and XML as the encoding. XML-RPC is designed to be as simple as possible, while allowing complex data structures to be transmitted, processed and returned. See: http://xmlrpc.scripting.com/spec See: http://xmlrpc.scripting.com/

  4. Local Method Call (not distributed) public class HelloWorldExample { public static String getGreeting() { return "Hello from this method."; } public static void main (String [] args) { String str = getGreeting(); System.out.println(str); } } calls

  5. Method Caller of the Method Local Method Call (not distributed) public class HelloWorldExample { public static String getGreeting() { return "Hello from this method."; } public static void main (String [] args) { String str = getGreeting(); System.out.println(str); } }

  6. Server Client Remote Method Call (distributed) public class HelloWorldExample { public static String getGreeting() { return "Hello from this method."; } public static void main (String [] args) { String str = getGreeting(); System.out.println(str); } }

  7. Java C++ Different Programming Languages? public class HelloWorldExample { public static String getGreeting() { return "Hello from this method."; } void main () { cout << getGreeting() << endl; } }

  8. Client and Server have to understand each other Wieviel Uhr ist es? ? Server Client

  9. Client and Server agree on a common language. Quelle heure est-il? 7pm! What’s the time? Wieviel Uhr ist es? Server Client

  10. The client encodes the information in the “common language”, the server decodes the information. Decode Encode Quelle heure est-il? What’s the time? Wieviel Uhr ist es? Server Client

  11. XML-RPC uses XML as a common language to transmit data Decode Encode Java C++ Python etc. XML Java C++ Python etc. Server Client

  12. That explains the XML in XML-RPC but what means RPC? RPC means “Remote Procedure Call”, that means you call a procedure (i.e. method, function) on a different machine.

  13. zz z RPC - Remote Procedure CallWhat is it? • RPC is a technique for constructing distributed, client-server based applications. • It is based on extending the notion of conventional, or local procedure calling. • As “remote” suggests, the called procedure need not to 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 architectures, programmers of distributed applications avoid the details of the interface with the network.

  14. Typical flow of control in RPCs • 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.

  15. XML-RPC and Java: The basic idea XML A Java package with specialist methods. A Java package with specialist methods. Method: getGreeting()(Server) Main program (Client) Specialist methods in the Java package org.apache.xmlrpc link the local code to the remote code.

  16. www.xmlrpc.com

  17. What is XML-RPC? • It's a specand a set of implementations that allow software running on disparate operating systems, running in different environments to make procedure calls over the Internet • It's remote procedure calling using HTTP as the transport and XML as the encoding. XML-RPC is designed to be as simple as possible, while allowing complex data structures to be transmitted, processed and returned.

  18. The specification, < 1800 words, is lightweight and easy to learn. Contains many examples. • It's a specand a set of implementations that allow software running on disparate operating systems, running in different environments to make procedure calls over the Internet • It's remote procedure calling using HTTP as the transport and XML as the encoding. XML-RPC is designed to be as simple as possible, while allowing complex data structures to be transmitted, processed and returned.

  19. Languages include: C/C++, Java, Perl, Python, Frontier, Lisp, PHP, Microsoft .NET, Rebol, Real Basic, Tcl, Delphi, WebObjects and Zope • It's a specand a set of implementations that allow software running on disparate operating systems, running in different environments to make procedure calls over the Internet • It's remote procedure calling using HTTP as the transport and XML as the encoding. XML-RPC is designed to be as simple as possible, while allowing complex data structures to be transmitted, processed and returned.

  20. Uses existing protocols (HTTP) and a well established framework (XML). • It's a spec and a set of implementations that allow software running on disparate operating systems, running in different environments to make procedure calls over the Internet • It's remote procedure calling usingHTTPas the transport andXMLas the encoding. XML-RPC is designed to be as simple as possible, while allowing complex data structures to be transmitted, processed and returned.

  21. The following data structures are supported: integer, boolean, string, double, date & time, base64 binaries, structs, arrays. • It's a specand a set of implementations that allow software running on disparate operating systems, running in different environments to make procedure calls over the Internet • It's remote procedure calling using HTTP as the transport and XML as the encoding. XML-RPC is designed to be as simple as possible, while allowing complex data structures to be transmitted, processed and returned.

  22. 1. Writing Server and Client 2. Identify 3. Communicate 1. Write Client Clientkdfjshkdsahfkdashfkajshfkdsjhkjsahfkdshfkhasdfkashfkdjsahfkshdfkhsafkjshfkdsfhakjdhfksjdhfakhsfkjsdfkdasjfkdasjksdajfkdsafhksajhkdjfhkasjkdsahksdjfksakdjsfksakshfdkjfdkdsfh Client Serverkdfjshkdsahfkdashfkajshfkdsjhkjsahfkdshfkhasdfkashfkdjsahfkshdfkhsafkjshfkdsfhakjdhfksjdhfakhsfkjsdfkdasjfkdasjksdajfkdsafhksajhk assfksakshfdkjf 10010101101110101 Server Server

  23. Example: An XML-RPC client/server application in Java. • The Java package org.apache.xmlrpc provides classes to implement an XML-RPC client and an XML-RPC server. The package can be found at http://ws.apache.org/xmlrpc/ • A copy of the package is under the name cis69mc.jar on http://perisic.com/xmlrpc.

  24. A Java “Hello World” Server import org.apache.xmlrpc.*; public class HelloWorldServer { public String getGreeting() { return "Hello from far away."; } public static void main (String [] args) { try { WebServer server = new WebServer(80); server.addHandler("hello", new HelloWorldServer()); server.start(); } catch (Exception ex) { System.err.println("There is a problem:" + ex); } } }

  25. A Java “Hello World” Server import org.apache.xmlrpc.*; public class HelloWorldServer { public String getGreeting() { return "Hello from far away."; } public static void main (String [] args) { try { WebServer server = new WebServer(80); server.addHandler("hello", new HelloWorldServer()); server.start(); } catch (Exception ex) { System.err.println("There is a problem:" + ex); } } } • The package org.apache.xmlrpc contains the class WebServer for a XML-RPC Server implementation

  26. A Java “Hello World” Server import org.apache.xmlrpc.*; public class HelloWorldServer { public String getGreeting() { return "Hello from far away."; } public static void main (String [] args) { try { WebServer server = new WebServer(80); server.addHandler("hello", new HelloWorldServer()); server.start(); } catch (Exception ex) { System.err.println("There is a problem:" + ex); } } } • The procedure that is called remotely is implemented as a public method in a class. • An instance of this class is then associated with a handler that is accessible by the client.

  27. A Java “Hello World” Server • The server is initialised by the port number (here: 80). • The server starts to listen at port 80. import org.apache.xmlrpc.*; public class HelloWorldServer { public String getGreeting() { return "Hello from far away."; } public static void main (String [] args) { try { WebServer server = new WebServer(80); server.addHandler("hello", new HelloWorldServer()); server.start(); } catch (Exception ex) { System.err.println("There is a problem:" + ex); } } }

  28. A Java “Hello World” Server • When problems occur (ie. a different process already listening on port 80) an Exception is thrown and has to be caught. import org.apache.xmlrpc.*; public class HelloWorldServer { public String getGreeting() { return "Hello from far away."; } public static void main (String [] args) { try { WebServer server = new WebServer(80); server.addHandler("hello", new HelloWorldServer()); server.start(); } catch (Exception ex) { System.err.println("There is a problem:" + ex); } } }

  29. About Port 80 • An advantage of using port 80 is that it is usually not blocked by firewalls. Port 80 is the default port used for the World Wide Web. Using port 80 justifies the word “Web” for this kind of Service: Web Service. • Note that you cannot have two programs using the same port on the same computer. That means, for instance, that you cannot run two XML-RPC server at the same time (however you may use different ports, e.g. 81 or 8080)

  30. A Java XML-RPC Client for the “HelloWorld” Web Service import org.apache.xmlrpc.*; import java.util.Vector; public class HelloWorldClient { public static void main (String [] args) { try { XmlRpcClient server = new XmlRpcClient("http://localhost/RPC2"); Vector params = new Vector(); Object result = server.execute("hello.getGreeting", params); System.out.println("Result from Server: "+ result.toString()); } catch (Exception ex) { System.err.println("HelloClient: " + ex); } } }

  31. A Java XML-RPC Client for the “HelloWorld” Service • The Java package org.apache.xmlrpc contains classes for XML-RPC Java clients and XML-RPC server. ie. XmlRpcClient. • The package java.util is necessary for the Vector class. import org.apache.xmlrpc.*; import java.util.Vector; public class HelloWorldClient { public static void main (String [] args) { try { XmlRpcClient server = new XmlRpcClient("http://localhost/RPC2"); Vector params = new Vector(); Object result = server.execute("hello.getGreeting", params); System.out.println("Result from Server: "+ result.toString()); } catch (Exception ex) { System.err.println("HelloClient: " + ex); } } }

  32. A Java XML-RPC Client for the “HelloWorld” Server • This line sends the request to the server. The procedure getGreeting() is called on the server as if it were a local procedure. The return value of a procedure call is always an Object. • “hello” denotes a handler that is defined in the server. import org.apache.xmlrpc.*; import java.util.Vector; public class HelloWorldClient { public static void main (String [] args) { try { XmlRpcClient server = new XmlRpcClient("http://localhost/RPC2"); Vector params = new Vector(); Object result = server.execute("hello.getGreeting", params); System.out.println("Result from Server: "+ result.toString()); } catch (Exception ex) { System.err.println("HelloClient: " + ex); } } }

  33. A Java XML-RPC Client for the “HelloWorld” Server • The parameters of the procedure call are always collected in a Vector. • In this example the procedure has no parameters. import org.apache.xmlrpc.*; import java.util.Vector; public class HelloWorldClient { public static void main (String [] args) { try { XmlRpcClient server = new XmlRpcClient("http://localhost/RPC2"); Vector params = new Vector(); Object result = server.execute("hello.getGreeting", params); System.out.println("Result from Server: "+ result.toString()); } catch (Exception ex) { System.err.println("HelloClient: " + ex); } } }

  34. A Java XML-RPC Client for the “HelloWorld” Server import org.apache.xmlrpc.*; import java.util.Vector; public class HelloWorldClient { public static void main (String [] args) { try { XmlRpcClient server = new XmlRpcClient("http://localhost/RPC2"); Vector params = new Vector(); Object result = server.execute("hello.getGreeting", params); System.out.println("Result from Server: "+ result.toString()); } catch (Exception ex) { System.err.println("HelloClient: " + ex); } } }

  35. A Java XML-RPC Client for the “HelloWorld” Server • The XmlRpcClient class is constructed by specifying the “web address” of the server machine followed by /RPC2. E.g. • localhost - means the local machine. • An IP number, e.g. 194.80.215.219 • A name, e.g. cis69.dyndns.org • All of the above, followed by a port number, e.g. cis69.dyndns.org:8080. The default port is 80. import org.apache.xmlrpc.*; import java.util.Vector; public class HelloWorldClient { public static void main (String [] args) { try { XmlRpcClient server = new XmlRpcClient("http://localhost/RPC2"); Vector params = new Vector(); Object result = server.execute("hello.getGreeting", params); System.out.println("Result from Server: "+ result.toString()); } catch (Exception ex) { System.err.println("HelloClient: " + ex); } } }

  36. 2. Identification of the Remote Service 2. Identify 3. Communicate 1. Write Client Clientkdfjshkdsahfkdashfkajshfkdsjhkjsahfkdshfkhasdfkashfkdjsahfkshdfkhsafkjshfkdsfhakjdhfksjdhfakhsfkjsdfkdasjfkdasjksdajfkdsafhksajhkdjfhkasjkdsahksdjfksakdjsfksakshfdkjfdkdsfh Client Serverkdfjshkdsahfkdashfkajshfkdsjhkjsahfkdshfkhasdfkashfkdjsahfkshdfkhsafkjshfkdsfhakjdhfksjdhfakhsfkjsdfkdasjfkdasjksdajfkdsafhksajhk assfksakshfdkjf 10010101101110101 Server Server

  37. Localhost and remote hosts • In our example Server and Client are running on the same Computer. Hence we can use the address http://localhost/RPC2. • If you are using the program on two machines that are connected to the Internet, use the IP address of the Server machine to make the connection (for instance http://123.45.67.89/RPC2). You can find the IP address of a computer with the program ipconfig. • If the Server machine is registered with a name (as ie. http://perisic.com ) You can use the name instead of the IP address (ie. http://perisic.com/RPC2). • The suffix “/RPC2” is used by some Web Servers to discriminate between XML-RPC calls and other incoming calls (for instance requests for HTML pages)

  38. ? What do we need to tell the client so that it can connect to the Server? • For a remote procedure call via the XML-RPC protocol we need the following information on the client side: • The location of the remote service. • The name of the remote procedure. • The parameters of the remote procedure. • The return type of the remote procedure.

  39. 3. Communication between Client and Server 2. Identify 3. Communicate 1. Write Client Clientkdfjshkdsahfkdashfkajshfkdsjhkjsahfkdshfkhasdfkashfkdjsahfkshdfkhsafkjshfkdsfhakjdhfksjdhfakhsfkjsdfkdasjfkdasjksdajfkdsafhksajhkdjfhkasjkdsahksdjfksakdjsfksakshfdkjfdkdsfh Client Serverkdfjshkdsahfkdashfkajshfkdsjhkjsahfkdshfkhasdfkashfkdjsahfkshdfkhsafkjshfkdsfhakjdhfksjdhfakhsfkjsdfkdasjfkdasjksdajfkdsafhksajhk assfksakshfdkjf 10010101101110101 Server Server

  40. Client Server Request from Client to Server <?xml version="1.0" encoding="ISO-8859-1"?> <methodCall> <methodName>hello.getGreeting</methodName> <params></params> </methodCall> The name of the method that is to be called on the Server. (empty) list of parameters.

  41. Client Server Response from the Server to the Client <?xml version="1.0" encoding="ISO-8859-1"?> <methodResponse> <params> <param> <value>Hello from far away.</value> </param> </params> </methodResponse> The String that is returned to the Client from the Server.

  42. Simple Object Access Protocol • SOAP is another protocol for Client/Server applications. • The general principle is similar as XML-RPC by using XML as common language. • Also labelled as “lightweight”, but the specification is > 77000 words.

  43. SOAP and XML-RPC • Wikipedia (2005): “[XML-RPC] was first created by Dave Winer of UserLand Software in 1995 with Microsoft. However Microsoft considered it too simple, and started adding functionality. After several rounds of this, the standard was no longer so simple, and became what is now SOAP.” • So, XML-RPC is • An excellent starting point for understanding the principles behind SOAP. • More lightweight and easier to learn.

  44. Summary • In our example, Client and Server have been written in the XML-RPC architecture using the programming language Java on both the Client and Server side. • The remote service is identified via the IP number. • The communication protocol is based on XML. • This is a very simple form of a web service ie. predecessor of SOAP.

More Related