Introduction to Web Services Sabyasachi Ghosh [email_address]
Agenda Refresher: Networking/OSI Model Socket Programming Remote Procedure Calls  Refresher: XML Overview of XML RPC Introduction to Web Services/SOA Introduction to SOAP Refresher: HTTP Restful Architectures and RESTful Web Services Q&A
Client-Server Technology CLIENT SERVER NETWORK Request Request Request Response Response
The OSI Model
Introduction to Sockets Socket is an endpoint of a bidirectional inter-process communication flow across an IP-based computer network. Sockets are provided by the operating system and is mapped by the OS to a communicating application process or thread. The transport layer comprises two types of protocols, TCP (Transport Control Protocol) and UDP (User Datagram Protocol).  The most widely used programming interfaces for these protocols are sockets.
Sockets Sockets are generalized form of inter-process communication (IPC)
RPC – Remote Procedure Calls Remote Procedure Call (RPC) is an inter-process communication that allows a computer program to cause a subroutine or procedure to execute in another address space. RPC (Remote Procedure Call) goes back at least as far as 1976, when it was described in RFC 707. Ref: Wikipedia
RPC – How does it work ?  A client makes a call to the procedure in a remote machine (server) which has the business logic with appropriate parameters. The server receives the parameters and executes the procedure locally and then transmits the results back to the client.  The client receives the results.
RPC – More formally: The client calls the Client stub. The call is a local procedure call, with parameters pushed on to the stack in the normal way. The client stub packs the parameters into a message and makes a system call to send the message. Packing the parameters is called marshalling. The kernel sends the message from the client machine to the server machine. The kernel passes the incoming packets to the server stub. Finally, the server stub calls the server procedure. The reply traces the same in other direction. Ref: Wikipedia
XML: Introduction eXtensible Markup Language A simplified version of SGML [ Standard Generalized Markup Language ] Maintains the most useful parts of SGML Designed so that SGML can be delivered over the Web More flexible and adaptable than HTML Markup: Information added to a text to make its structure comprehensible
XML: Differences with HTML XML was designed to carry data, not displaying data XML is not a replacement for HTML. Different goals: XML was designed to describe data and to focus on what data is. HTML was designed to display data and to focus on how data looks. HTML is about displaying information, XML is about describing information.
XML: Example <?xml version=&quot;1.0&quot;?> < catalog >  < product   category = &quot;mobile phone&quot;> <mfg>Nokia</mfg><model>8890</model> <description> Intended for EGSM 900 and GSM 1900  networks … </description> <clock setting= &quot;nist&quot; alarm = &quot;yes&quot;/> </ product > < product  category = &quot;mobile phone&quot;>  <mfg>Ericsson</mfg><model>A3618</model> <description>...</description> </ product > </ catalog >
XML: More on it XML is a metalanguage, not a specific language. Defines the rules how to mark up a document - does not define the names used in markup. Includes capability to prescribe a XML Schema (XSD) to constrain the markup permitted in a class of documents. Intended for all natural languages, regardless of character set, orientation of script, etc.
XML RPC
JSON Object: collection of comma separated Attributes var object = { } Attributes: name-value pairs “ name”: “Duke” “ age”: 10 Array: List of comma separated objects [{“name”: “Duke”, “age”: 10}, {name:“Tux”, “age”: 20}] Data types (String, Number, boolean, array, object, null)
{ &quot;firstName&quot;: &quot;John&quot;, &quot;lastName&quot;: &quot;Smith&quot;, &quot;age&quot;: 25, &quot;address&quot;: { &quot;streetAddress&quot;: &quot;21 2nd Street&quot;, &quot;city&quot;: &quot;New York&quot;, &quot;state&quot;: &quot;NY&quot;, &quot;postalCode&quot;: &quot;10021&quot; }, &quot;phoneNumber&quot;: [ { &quot;type&quot;: &quot;home&quot;, &quot;number&quot;: &quot;212 555-1234&quot; }, { &quot;type&quot;: &quot;fax&quot;, &quot;number&quot;: &quot;646 555-4567&quot; }   ] }
What is a Web Service A web service is a piece of business logic, located somewhere on the Internet, that is accessible through standard-based Internet protocols such as HTTP or SMTP. Using a web service could be as simple as logging into a site or as complex as facilitating a multi-organization business negotiation.  Ex: Creating a Sales Order and initiating a workflow. Ref: Java Web Services, Chappel et al, O'Reilly
Web Services: Alternate definition A web service is just a web page meant for a computer to request and process. More precisely, a Web service is a Web page that’s meant to be consumed by an autonomous program as opposed to a Web browser or similar UI tool. Copyright 2005 John Cowan under GPL
Service Oriented Architecture As per Wikipedia, Service-oriented architecture (SOA) is a flexible set of design principles used during the phases of systems development and integration in computing. A system based on a SOA will package functionality as a suite of interoperable services that can be used within multiple separate systems from several business domains.
Service Oriented Architecture Requestor Providers Registry FIND , UDDI BIND , SOAP/WSDL PUBLISH,  UDDI
Components of SOA Participants: Provider Registry (broker) Requestor Interactions: Publishing Direct HTTP GET request Dynamic discovery Service location (finding) Binding
SOA: Publishing (dynamic) Provider Registry Here is my service !
SOA: Locating Service Requestor Registry Where is the service?  Find it here !
SOA: Binding Requestor Registry How can I access ? Here is how ! Provider What is the temperature today?  40 C
Characteristics of a Web Service XML-based Loosely coupled Coarse-grained Ability to be synchronous or asynchronous Supports Remote Procedure Calls Supports document exchange Ref: Java Web Services, Chappel et al, O'Reilly
Major Technologies for WS SOAP – Simple Object Access Protocol WSDL – Web Services Definition/Description Language UDDI –Universal Description, Discovery, and Integration Ref: Java Web Services, Chappel et al, O'Reilly
SOAP SOAP stands for Simple Object Access Protocol. It is based on XML. It is a wired protocol and was defined to be highly interoperable.  As of today there are extensive libraries support in virtually all languages to support SOAP based communication.
SOAP: Layers SOAP-ENV:Envelope SOAP-ENV:Header SOAP-ENV:Body
SOAP: Example POST /InStock HTTP/1.1 Host: www.example.org Content-Type: application/soap+xml; charset=utf-8 Content-Length: 299 <?xml version=&quot;1.0&quot;?> < soap:Envelope  xmlns:soap=&quot;http://www.w3.org/2003/05/soap-envelope&quot;> < soap:Header > </ soap:Header > < soap:Body > <m:GetStockPrice xmlns:m=&quot;http://www.example.org/stock&quot;> <m:StockName>IBM</m:StockName> </m:GetStockPrice> </ soap:Body > </ soap:Envelope >
Creating a SOAP message <student> <roll>120</roll> <firstName>Kiran</firstName> <lastName>Reddy</lastName> <grades> <english>A</english> <maths>B</maths> </grades> </student> <?xml version=&quot;1.0&quot;?> <soap:Envelope xmlns:soap=&quot;http://www.w3.org/2003/05/soap-envelope&quot;> <soap:Header> </soap:Header> <soap:Body> <student> <roll>120</roll> <firstName>Kiran</firstName> <lastName>Reddy</lastName> <grades> <english>A</english> <maths>B</maths> </grades> </student> </soap:Body> </soap:Envelope>
SOAP: Envelop The SOAP envelope declaration is simply the outermost XML tag that delineates the boundaries of the SOAP document.  The following envelope tag shows three required attributes, which specify the namespace and the schema to be used for this envelope: <SOAP-ENV:Envelope xmlns:SOAP-ENV=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot; xmlns:xsi=&quot;http://www.w3.org/1999/XMLSchema-instance&quot; xmlns:xsd=&quot;http://www.w3.org/1999/XMLSchema&quot;> ... </SOAP-ENV:Envelope>
SOAP: Header & Body The SOAP header and body are syntactically similar. It is simply a place to put directives to the SOAP processor that receives the message. The sending and receiving parties need to agree on which elements go there and what they mean.
SOAP: Fault SOAP errors are handled using a specialized envelope known as a Fault Envelope.  If an error occurs while the server processes a SOAP message, it constructs a SOAP Fault and sends it back to the client.
RESTful Architecture
HTTP: Introduction The Hypertext Transfer Protocol (HTTP) is an application-level protocol for distributed, collaborative, hypermedia information systems. HTTP has been in use by the World-Wide Web global information initiative since 1990.
HTTP: How does it work? The HTTP protocol is a request/response protocol. A client sends a request to the server in the form of a request method, URI, and protocol version, followed by a MIME-like message containing request modifiers, client information, and possible body content over a connection with a server.
HTTP: How does it work? The server responds with a status line, including the message's protocol version and a success or error code, followed by a MIME-like message containing server information, entity meta information, and possible entity-body content.
HTTP: Request/Response Client Request GET /vnav/labs/PHP/HTTP.php HTTP/1.1 Host: loadaveragezero.com User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.14) Gecko/20110218 Firefox/3.6.14 (.NET CLR 3.5.30729) Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 ... Server Response HTTP/1.1 200 OK Server: Apache/1.3.41 (Unix) Content-type: application/xhtml+xml; charset=UTF-8 ...
What is REST? REST stands for Representational State Transfer.  Its basically a stateless communication protocol relying on lightweight protocols like HTTP. It is basically an architectural design methodology.
REST: The other verbs GET to retrieve information POST to add new information, showing its relation to old information PUT to update information DELETE to discard information
RESTful Application Cycle Resources are identified by URIs ↓ Clients communicate with resources via requests using astandard set of methods ↓ Requests and responses contain resource representations informats identified by media types ↓ Responses contain URIs that link to further resources
REST: Give Everything an ID ID is a URI http://example.com/widgets/foo http://example.com/customers/bar http://example.com/customers/bar/orders/2 http://example.com/orders/101230/customer
Q & A Thank You!

Intro to web services

  • 1.
    Introduction to WebServices Sabyasachi Ghosh [email_address]
  • 2.
    Agenda Refresher: Networking/OSIModel Socket Programming Remote Procedure Calls Refresher: XML Overview of XML RPC Introduction to Web Services/SOA Introduction to SOAP Refresher: HTTP Restful Architectures and RESTful Web Services Q&A
  • 3.
    Client-Server Technology CLIENTSERVER NETWORK Request Request Request Response Response
  • 4.
  • 5.
    Introduction to SocketsSocket is an endpoint of a bidirectional inter-process communication flow across an IP-based computer network. Sockets are provided by the operating system and is mapped by the OS to a communicating application process or thread. The transport layer comprises two types of protocols, TCP (Transport Control Protocol) and UDP (User Datagram Protocol). The most widely used programming interfaces for these protocols are sockets.
  • 6.
    Sockets Sockets aregeneralized form of inter-process communication (IPC)
  • 7.
    RPC – RemoteProcedure Calls Remote Procedure Call (RPC) is an inter-process communication that allows a computer program to cause a subroutine or procedure to execute in another address space. RPC (Remote Procedure Call) goes back at least as far as 1976, when it was described in RFC 707. Ref: Wikipedia
  • 8.
    RPC – Howdoes it work ? A client makes a call to the procedure in a remote machine (server) which has the business logic with appropriate parameters. The server receives the parameters and executes the procedure locally and then transmits the results back to the client. The client receives the results.
  • 9.
    RPC – Moreformally: The client calls the Client stub. The call is a local procedure call, with parameters pushed on to the stack in the normal way. The client stub packs the parameters into a message and makes a system call to send the message. Packing the parameters is called marshalling. The kernel sends the message from the client machine to the server machine. The kernel passes the incoming packets to the server stub. Finally, the server stub calls the server procedure. The reply traces the same in other direction. Ref: Wikipedia
  • 10.
    XML: Introduction eXtensibleMarkup Language A simplified version of SGML [ Standard Generalized Markup Language ] Maintains the most useful parts of SGML Designed so that SGML can be delivered over the Web More flexible and adaptable than HTML Markup: Information added to a text to make its structure comprehensible
  • 11.
    XML: Differences withHTML XML was designed to carry data, not displaying data XML is not a replacement for HTML. Different goals: XML was designed to describe data and to focus on what data is. HTML was designed to display data and to focus on how data looks. HTML is about displaying information, XML is about describing information.
  • 12.
    XML: Example <?xmlversion=&quot;1.0&quot;?> < catalog > < product category = &quot;mobile phone&quot;> <mfg>Nokia</mfg><model>8890</model> <description> Intended for EGSM 900 and GSM 1900 networks … </description> <clock setting= &quot;nist&quot; alarm = &quot;yes&quot;/> </ product > < product category = &quot;mobile phone&quot;> <mfg>Ericsson</mfg><model>A3618</model> <description>...</description> </ product > </ catalog >
  • 13.
    XML: More onit XML is a metalanguage, not a specific language. Defines the rules how to mark up a document - does not define the names used in markup. Includes capability to prescribe a XML Schema (XSD) to constrain the markup permitted in a class of documents. Intended for all natural languages, regardless of character set, orientation of script, etc.
  • 14.
  • 15.
    JSON Object: collectionof comma separated Attributes var object = { } Attributes: name-value pairs “ name”: “Duke” “ age”: 10 Array: List of comma separated objects [{“name”: “Duke”, “age”: 10}, {name:“Tux”, “age”: 20}] Data types (String, Number, boolean, array, object, null)
  • 16.
    { &quot;firstName&quot;: &quot;John&quot;,&quot;lastName&quot;: &quot;Smith&quot;, &quot;age&quot;: 25, &quot;address&quot;: { &quot;streetAddress&quot;: &quot;21 2nd Street&quot;, &quot;city&quot;: &quot;New York&quot;, &quot;state&quot;: &quot;NY&quot;, &quot;postalCode&quot;: &quot;10021&quot; }, &quot;phoneNumber&quot;: [ { &quot;type&quot;: &quot;home&quot;, &quot;number&quot;: &quot;212 555-1234&quot; }, { &quot;type&quot;: &quot;fax&quot;, &quot;number&quot;: &quot;646 555-4567&quot; } ] }
  • 17.
    What is aWeb Service A web service is a piece of business logic, located somewhere on the Internet, that is accessible through standard-based Internet protocols such as HTTP or SMTP. Using a web service could be as simple as logging into a site or as complex as facilitating a multi-organization business negotiation. Ex: Creating a Sales Order and initiating a workflow. Ref: Java Web Services, Chappel et al, O'Reilly
  • 18.
    Web Services: Alternatedefinition A web service is just a web page meant for a computer to request and process. More precisely, a Web service is a Web page that’s meant to be consumed by an autonomous program as opposed to a Web browser or similar UI tool. Copyright 2005 John Cowan under GPL
  • 19.
    Service Oriented ArchitectureAs per Wikipedia, Service-oriented architecture (SOA) is a flexible set of design principles used during the phases of systems development and integration in computing. A system based on a SOA will package functionality as a suite of interoperable services that can be used within multiple separate systems from several business domains.
  • 20.
    Service Oriented ArchitectureRequestor Providers Registry FIND , UDDI BIND , SOAP/WSDL PUBLISH, UDDI
  • 21.
    Components of SOAParticipants: Provider Registry (broker) Requestor Interactions: Publishing Direct HTTP GET request Dynamic discovery Service location (finding) Binding
  • 22.
    SOA: Publishing (dynamic)Provider Registry Here is my service !
  • 23.
    SOA: Locating ServiceRequestor Registry Where is the service? Find it here !
  • 24.
    SOA: Binding RequestorRegistry How can I access ? Here is how ! Provider What is the temperature today? 40 C
  • 25.
    Characteristics of aWeb Service XML-based Loosely coupled Coarse-grained Ability to be synchronous or asynchronous Supports Remote Procedure Calls Supports document exchange Ref: Java Web Services, Chappel et al, O'Reilly
  • 26.
    Major Technologies forWS SOAP – Simple Object Access Protocol WSDL – Web Services Definition/Description Language UDDI –Universal Description, Discovery, and Integration Ref: Java Web Services, Chappel et al, O'Reilly
  • 27.
    SOAP SOAP standsfor Simple Object Access Protocol. It is based on XML. It is a wired protocol and was defined to be highly interoperable. As of today there are extensive libraries support in virtually all languages to support SOAP based communication.
  • 28.
    SOAP: Layers SOAP-ENV:EnvelopeSOAP-ENV:Header SOAP-ENV:Body
  • 29.
    SOAP: Example POST/InStock HTTP/1.1 Host: www.example.org Content-Type: application/soap+xml; charset=utf-8 Content-Length: 299 <?xml version=&quot;1.0&quot;?> < soap:Envelope xmlns:soap=&quot;http://www.w3.org/2003/05/soap-envelope&quot;> < soap:Header > </ soap:Header > < soap:Body > <m:GetStockPrice xmlns:m=&quot;http://www.example.org/stock&quot;> <m:StockName>IBM</m:StockName> </m:GetStockPrice> </ soap:Body > </ soap:Envelope >
  • 30.
    Creating a SOAPmessage <student> <roll>120</roll> <firstName>Kiran</firstName> <lastName>Reddy</lastName> <grades> <english>A</english> <maths>B</maths> </grades> </student> <?xml version=&quot;1.0&quot;?> <soap:Envelope xmlns:soap=&quot;http://www.w3.org/2003/05/soap-envelope&quot;> <soap:Header> </soap:Header> <soap:Body> <student> <roll>120</roll> <firstName>Kiran</firstName> <lastName>Reddy</lastName> <grades> <english>A</english> <maths>B</maths> </grades> </student> </soap:Body> </soap:Envelope>
  • 31.
    SOAP: Envelop TheSOAP envelope declaration is simply the outermost XML tag that delineates the boundaries of the SOAP document. The following envelope tag shows three required attributes, which specify the namespace and the schema to be used for this envelope: <SOAP-ENV:Envelope xmlns:SOAP-ENV=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot; xmlns:xsi=&quot;http://www.w3.org/1999/XMLSchema-instance&quot; xmlns:xsd=&quot;http://www.w3.org/1999/XMLSchema&quot;> ... </SOAP-ENV:Envelope>
  • 32.
    SOAP: Header &Body The SOAP header and body are syntactically similar. It is simply a place to put directives to the SOAP processor that receives the message. The sending and receiving parties need to agree on which elements go there and what they mean.
  • 33.
    SOAP: Fault SOAPerrors are handled using a specialized envelope known as a Fault Envelope. If an error occurs while the server processes a SOAP message, it constructs a SOAP Fault and sends it back to the client.
  • 34.
  • 35.
    HTTP: Introduction TheHypertext Transfer Protocol (HTTP) is an application-level protocol for distributed, collaborative, hypermedia information systems. HTTP has been in use by the World-Wide Web global information initiative since 1990.
  • 36.
    HTTP: How doesit work? The HTTP protocol is a request/response protocol. A client sends a request to the server in the form of a request method, URI, and protocol version, followed by a MIME-like message containing request modifiers, client information, and possible body content over a connection with a server.
  • 37.
    HTTP: How doesit work? The server responds with a status line, including the message's protocol version and a success or error code, followed by a MIME-like message containing server information, entity meta information, and possible entity-body content.
  • 38.
    HTTP: Request/Response ClientRequest GET /vnav/labs/PHP/HTTP.php HTTP/1.1 Host: loadaveragezero.com User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.14) Gecko/20110218 Firefox/3.6.14 (.NET CLR 3.5.30729) Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 ... Server Response HTTP/1.1 200 OK Server: Apache/1.3.41 (Unix) Content-type: application/xhtml+xml; charset=UTF-8 ...
  • 39.
    What is REST?REST stands for Representational State Transfer. Its basically a stateless communication protocol relying on lightweight protocols like HTTP. It is basically an architectural design methodology.
  • 40.
    REST: The otherverbs GET to retrieve information POST to add new information, showing its relation to old information PUT to update information DELETE to discard information
  • 41.
    RESTful Application CycleResources are identified by URIs ↓ Clients communicate with resources via requests using astandard set of methods ↓ Requests and responses contain resource representations informats identified by media types ↓ Responses contain URIs that link to further resources
  • 42.
    REST: Give Everythingan ID ID is a URI http://example.com/widgets/foo http://example.com/customers/bar http://example.com/customers/bar/orders/2 http://example.com/orders/101230/customer
  • 43.
    Q & AThank You!