Lecture 15: Frameworks for Application-layer Communications Prof. Shervin Shirmohammadi SITE, University of Ottawa Fall 2005 CEG 4183 15-1
Background We have seen previously that: Applications need to exchange messages In the labs, the assignments, and the project, we used application-level framing that uses application-specific tokens. Whiteboard example Fall 2005 CEG 4183 15-2
Motivation Token-based messaging scheme can become complicated as the application adds more and more features. Think of the number of commands in a word-processor applications. There should be a way for a more methodical and structured technique to allow programs to communicate. Ideally, the programmer should not even have to worry about communication and how it s done. Enter communications frameworks: RPC, RMI, CORBA, SOAP Fall 2005 CEG 4183 15-3
Remote Procedure Call RPC, used in C and C++ (theoretically language neutral) The idea goes back to 1976, with full-scale implementations appearing in the late 1970s. We know that in a program, functions can call one another. Even different programs running on the same computer can call each other s function. e.g., OLE on Windows, pipes on UNIX, The idea behind RPC is to allow the same thing for programs running on different computers. A program on my computer should be able to call a function inside a program on your computer. Fall 2005 CEG 4183 15-4
RPC Host 1 Host 2 main.c void main() { compute(3, 5); int compute() { return x+y/x; compute.c int compute() { return x+y/x; compute.c Somehow we have to transmit the return value (which can be anything: integer, array, linked list, ) over the network. What else must we take care of? Fall 2005 CEG 4183 15-5
RPC Details During compilation, client and server stubs are created. Application calls a function from the client stub, which converts arguments to Network Data Representation (NDR) and sends them to the RPC run-time. Run-time uses the transport layer to send data to server. Server s RPC run-time takes the incoming data and passes them to server s stub, which runs the actual procedure. Result is returned similarly. Fall 2005 CEG 4183 15-6
Remote Method Invocation RMI, used in Java only. Can be thought of as Object-oriented RPC. Host 1 Host 2 main.java void main() { Local.compute(3, 5); int compute() { return x+y/x; int compute() { return x+y/x; Remote.compute(3,5); Local.java Remote.java How to send objects over the network? Fall 2005 CEG 4183 15-7
RMI Details Stub (remote object) and skeleton (server object) is created. Stubs don t need to be compiled into the client, they can be downloaded at run-time. Remote objects are registered, and clients can download their stub to use their services. Application invokes remote object s stub as if invoking a local object. Stub passes the arguments to Remote Reference Layer which then uses the transport layer for network communication. RRL at server invokes the skeleton, which invokes the actual object to do the operation. The result is sent back in a similar manner. Fall 2005 CEG 4183 15-8
RMI Example Time server example in RMI First, we define the service available by describing its methods. No implementation is needed at this stage users don t care anyway about the internal implementation, they just want to be able to call the function. Defining the interface: TimeInterface.java: import java.rmi.*; public interface TimeInterface extends Remote { public String gettime() throws RemoteException; Fall 2005 CEG 4183 15-9
RMI Example: Remote Object Now we need to implement that Interface Time.java: import java.rmi.*; import java.rmi.server.*; public class Time extends UnicastRemoteObject implements TimeInterface { public String gettime() throws RemoteException { return "It's 12PM"; Fall 2005 CEG 4183 15-10
We need to run the service: Server.java: import java.rmi.naming; public Server { RMI Example: Server public static void main (String[] argv) { try { Naming.rebind ("Time", new Time()); System.out.println ("Time Server is running."); catch (Exception e) { System.out.println ("Problem with Time Server: " + e); Fall 2005 CEG 4183 15-11
RMI Example: Client Finally, we can write a client program that uses the Time service: Client.java: import java.rmi.naming; public Client { public static void main (String[] argv) { try { TimeInterfacce time_object = (TimeInterface) Naming.lookup ("137.122.20.16/Time"); System.out.println (time_object.gettime()); catch (Exception e) { System.out.println ("Exception: " + e); Fall 2005 CEG 4183 15-12
CORBA Common Object Request Broker Architecture, an Object Management Group (OMG) standard Cross-platform, language-independent! Provides services to enable an application in a given programming language to talk to a remote application using another programming language, both running on different platforms. Includes many services for registry, lookup, naming, and so on. Uses Interface Definition Language (IDL) to specify method signatures (return type, name, arguments). IDL is platform-independent, and defines its own types. Stub (client) and skeleton (server) is created during compilation. These have to be implemented in a language-specific manner. Binding is done during run-time. Fall 2005 CEG 4183 15-13
CORBA Scenario Host 1 Win 95 Host 2 Solaris void main() { compute(3, 5); main.c int compute() { return x+y/x; Remote.java Fall 2005 CEG 4183 15-14
SOAP Simple Object Access Protocol, a W3C standard, is a communications protocol to exchange messages among applications. Typically used on top of HTTP. Doesn t have to be HTTP. An XML-based application-layer communications technique. The idea is, similar to RPC RMI and CORBA, to hide the communication part and let the application-layer on one side to talk to the application layer on the other side. Part of the Web Services paradigm. What is a Web Service? A Web page that provides a a service? Fall 2005 CEG 4183 15-15
IBM Evolution of Networked Applications Fall 2005 CEG 4183 15-16
Web Evolution XML XML HTML HTML TCP/IP TCP/IP Technology Technology Connectivity Presentation Programmability FTP, E-mail, Gopher Innovation Innovation Web Pages mail, Gopher Web Pages Web Services Services Browse the Web Program the Web Fall 2005 CEG 4183 15-17
Web Services are: a solution for providing application-to-application communication over the Internet. a URL-addressable software resource that performs functions. Web services communicate using standard protocol known as SOAP (Simple Object Access Protocol) A Web services is located by its listing in a Universal Discovery, Description and Integration (UDDI) directory. A Web Service is typically defined using the Web Service Definition Language (WSDL) Requester Broker Provider Service Requester Discover / describe WSDL UDDI Service Broker Publish / describe WSDL UDDI Service Provider Bind SOAP Fall 2005 CEG 4183 15-18 XML
Architecture Request & Response Service Tier SOAP or XML-RPC HTTP SOAP or XML-RPC HTTP Listener Web Services API CORBA, RMI, DCOM, JMS middleware Business Services SOAP and XML-RPC have become accepted standards for XML-based messaging. HTTP is the protocol for the Internet. The Web Service will parse the request and either fulfill the request directly, or invoke one or more business services via some middleware API. Fall 2005 CEG 4183 15-19
Extensible Markup Language (XML) XML is a metadata language: data that describes data. It is used as a standard way for information exchange. W3C standard In some ways it can be thought as part of the presentation layer. It is a subset of SGML (Standard Generalized Markup Language) SGML is the parent of HTML The key to success of XML: it lets you define your own data types in a standard way. Processing XML: APIs (DOM, SAX) addressing XML: XPath, XLink, XPointer Fall 2005 CEG 4183 15-20
XML Element and Attributes Element <resource> <tutorial name= cooking"> <authors> <author>jane Smith</author> </authors> <title>the Joy of Cooking</title> </tutorial> Attribute </resource> Nice, but how do we know what are resource, tutorial, title,? Fall 2005 CEG 4183 15-21
Document Type Definitions (DTD) recursive types <!ELEMENT A (B C)> <!ELEMENT B (A C)> "an A can contain a B..." "... which contains an A!" <!ELEMENT C (#PCDATA)> loose typing <!ELEMENT A ANY> no context-sensitive types: DTDs cannot distinguish between the publisher in <journal> <publisher>... </publisher> </journal> <website> <publisher>... </publisher> </website> What do to in terms of conflicts such as this? Fall 2005 CEG 4183 15-22
XML Namespaces My element may not be your element: geometry context: <element>line</element> chemistry context: <element>oxygen</element> use XML namespaces to identify the vocabulary <?xml version="1.0" encoding="utf-8"?> <lists xmlns= http://deltabis.com/products xmlns:it="http://deltabis.com/itinerary"> <product sku="8822n" size="small" type="trouser"> <it:itinerary> <it:sold>120</it:sold>... Fall 2005 CEG 4183 15-23
Example <?xml version="1.0" encoding="utf-8"?> <lists xmlns= http://deltabis.com/products xmlns:it="http://deltabis.com/itinerary"> <product sku="8822n" size="small" type="trouser"> <it:itinerary> <it:sold>120</it:sold> <it:onhold>45</it:onhold> <it:returned>10</it:returned> </it:itinerary> </product> <product sku="9820y" size="small" type="tshirt"> <it:itinerary> <it:sold>283</it:sold> <it:onhold>232</it:onhold> <it:returned>23</it:returned> </it:itinerary> </product> </lists> Fall 2005 CEG 4183 15-24
WSDL Web Services Definition Language Standard for defining a Web Service Defines an abstract interface and bindings to particular message formats Defines how to locate the service (URLs for HTTP) Defines what protocol the service uses (HTTP, SMTP, FTP) Written in XML Used to publish services in UDDI Fall 2005 CEG 4183 15-25
UDDI Universal Discovery, Description and Integration Standard for publishing Web Services Directory service that enables clients to locate services Services can be found by searching or unique ID Servers provide a SOAP based interface (API) for finding and publishing Three roles for UDDI data White pages technical contact information and addresses Yellow pages various services available from business Green pages technical information about services including WSDL SOAP processor UDDI registry service Client application SOAP request SOAP response Web server UDDI database UDDI registry node Fall 2005 CEG 4183 15-26
Back to Web Services: SOAP SOAP provides transfer of structured data between services. SOAP is an XML based transport protocol. Protocol binding: HTTP, SMTP One way message: Sender or Receiver It is stateless, and therefore the sender and receiver need not maintain a session to communicate. The application however has to take care of the communications semantics. Fall 2005 CEG 4183 15-27
SOAP Details With SOAP, we re actually back to a concept which is similar to the familiar token-based message passing, but SOAP is standardized. Host 1 Host 2 void main() { getlowestprice(); main.c Give me lowest price for book lowest price is $67.99 Web service provider Fall 2005 CEG 4183 15-28
SOAP Request getlowestprice <?xml version="1.0"?> <soap:envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingstyle="http://www.w3.org/2001/12/soap-encoding"> <soap:body> <m:getprice mlns:m="http://www.w3schools.com/prices"> <m:item>isbn78932167</m:item> </m:getprice> </soap:body> </soap:envelope> This message is sent to the server using HTTP. Fall 2005 CEG 4183 15-29
SOAP Response Response: <?xml version="1.0"?> <soap:envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingstyle="http://www.w3.org/2001/12/soap-encoding"> <soap:body> <m:getprice mlns:m="http://www.w3schools.com/prices"> <m:price>67.99</m:price> </m:getprice> </soap:body> </soap:envelope> This message is returned to the requester. Fall 2005 CEG 4183 15-30