SlideShare una empresa de Scribd logo
1 de 54
Communication Protocols and Web Services Created by Omer Katz, 2010 Omer Katz © Some Rights Reserved
Structure of a standard networkingstack for the Web
Common serialization formats JSON Natively supported within JavaScript Capable of referencing other records by convention Human readable format Lightweight Easy to parse Uses JSON-Schema to validate itself Key-Value based syntax XML JavaScript exposes a proprietary DOM API Human readable format for hierarchal data Hard to parse Consumes more memory than JSON Supports XSLT and XPath Uses XML-Schema or DTD to validate itself Markup based syntax
What is a web service? A web service is typically an application programming interface (API) or Web API that is accessed via Hypertext Transfer Protocol (HTTP) and executed on a remote system, hosting the requested service. Web services do not provide the user with a GUI. Web services instead share business logic, data and processes through a programmatic interface across a network.  Developers can then add the Web service to a GUI (such as a Web page or an executable program) to offer specific functionality to users.
Web services communication protocols RPC XML-RPC HTTP Bound JSON-RPC SMD – Service Mapping Description JSONP Allows cross domain Ajax requests SOA SOAP XML Based Strongly typed WSDL dependant REST Stateless Cacheable Code On Demand Client and Server are unaware of each other’s state Layered System Uniform Interface Service may be described through SMD, WSDL, WADL or not at all
What is RPC? Remote Procedure Call. Allows to access server-side/inter-process operations from a client through a well-defined protocol. Examples: COBRA, XML-RPC, JSON-RPC, DCOM, RMI Client is tightly coupled with the server
JSON-RPC Request/Response model Request Notification Response Error Batch operations Advantages Lightweight JSON-Schemas can be extended to validate specific message Not bound to HTTP by the specification, but might be used with it Can be natively serialized from within JavaScript Service discovery can be achieved through SMD or WADL Disadvantages Procedural The web service's methods grow linearly with the number of client request types Not bound to a URI Conclusion Fits for low resources environment (embedded devices) Does not fit for rapidly growing web services Does not fit for web services operating on many entities unless the web service is an HTTP service
JSON-RPC Examples A Notification: {     ”jsonrpc”: ”2.0”,     ”method”: ”update”,     ”params”: [1,2,3,4,5] }
JSON-RPC Examples A Request {     ”jsonrpc”: ”2.0”,     ”method”: ”subtract”,     ”params”: {                    ”subtrahend”: 23,                    ”minuend”: 42                },     ”id”: 3 }
JSON-RPC Examples An Error: { 	”jsonrpc”: ”2.0”, 	”error”: { 			”code”: -32601,  			”message”: ”Procedure not found.” 		        }, 	”id”: ”1” }
JSON-RPC Examples Batch Request: [{ 		”jsonrpc”: ”2.0”,  		”method”: ”sum”, 		”params”: [1,2,4], 		”id”: ”1” 	},{ 		”jsonrpc”: ”2.0”, 		”method”: ”notify_hello”, 		”params”: [7] 	},{ 		”jsonrpc”: ”2.0”, 		”method”: ”subtract”, 		”params”: [42,23], 		”id”: ”2” 	} ]
JSON-RPC Examples Batch Response: [ 	{      ”jsonrpc”:”2.0”,      ”result”:7,      ”id”:”1” }, {      ”jsonrpc”:”2.0”,      ”result”:19,      ”id”:”2    	},{      ”jsonrpc”:”2.0”,      ”error”:{         ”code”:-32601,         ”message”:” Procedure not found.”      },      ”id”:”5” 	}, ]
XML-RPC Request/Response model Request Response Error Advantages Bound to a URI Can represent hierarchical data in a readable way XSLT & XPath Can be validated through XML-Schema or DTD Disadvantages Procedural The web service's methods grow linearly with the number of client request types Bound to HTTP Only appropriate for the web Hard to parse Heavy payload Consumes a lot of memory No bulk operations Conclusion Does not fit for rapidly growing web services Does not fit for embedded devices Fits to represent hierarchical data
XML-RPC Examples Request:  <?xml version=”1.0”?><methodCall> 			<methodName>examples.getStateName</methodName>            <params>                <param>                    <value>                        <i4>40</i4>                    </value>                </param>            </params></methodCall>
XML-RPC Examples Response: <?xml version=”1.0”?>    <methodResponse>        <params><param>                <value>                    <string>South Dakota</string>                </value>            </param>        </params>    </methodResponse>
XML-RPC Examples Error: <?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>
What is SOA? Service Oriented Architecture. Allows to access server-side from a client through a well-defined protocol. Examples: SOAP, REST, SOAPjr Client does not have to be tightly coupled with the server. Unlike RPC based web services which usually are not discoverable there is a way to discover services in SOA based web service.
Service Description Standards WSDL Web Services Description Language Well known Verbose Uses XML Not human readable Used by WCF Feels natural for SOAP services Endorsed by Microsoft WSDL 1.1 supports only GET and POST requests
Service Description Standards - Continued WADL Web Application Description Language Not very well known A bit less verbose than WSDL Uses XML A bit more human readable Used by Java Feels natural for REST Services Endorsed by Sun Microsystems
Service Description Standards - Continued SMD Service Mapping Description  Working Draft status Less verbose Uses JSON Human readable Used by the Dojo Toolkit Not stable Endorsed by Sitepen and The Dojo Foundation
WSDL Example <description> <types>    <schema>        <element name=”myMethod”>            <complexType>                <sequence>                    <element name=”x” type=”xsd:int”/>                    <element name=”y” type=”xsd:float”/>                </sequence>            </complexType>        </element>        <element name=”myMethodResponse”>            <complexType/>        </element>    </schema></types>…
WSDL Example   <message name=”myMethodRequest”>    <part name=”parameters” element=”myMethod”/></message><message name=”empty”>    <part name=”parameters” element=”myMethodResponse”/></message><portTypename=”PT”>    <operation name=”myMethod”>        <input message=”myMethodRequest”/>        <output message=”empty”/>    </operation></portType> Hold your horses, there’s more…
WSDL Example       <binding interface=”...”>        <!-- The binding of a protocol to an interface, same structure              as the interface element -->     </binding>     <service interface=”...”>        <!-- Defines the actual addresses of the bindings, as in 1.1,              but now ”ports” are called ”endpoints” -->        <endpoint binding=”...” address=”...”/>     </service></description> And it goes on and on… I actually tried to keep it short.
Have I already mentioned that WSDL is verbose?
SMD Example { 	target:”/jsonrpc”, // this defines the URL to connect for the services transport:”POST”, // We will use POST as the transport envelope:”JSON-RPC-1.2”, // We will use JSON-RPC SMDVersion:”2.0”, services: {   add : { // define a service to add two numbers   parameters: [     {name:”a”,type:”number”}, // define the two parameters     {name:”b”,type:”number”}],   returns:{”type”:”number”} }, foo : {   // nothing is required to be defined, all definitions are optional.   //This service has nothing defined so it can take any parameters   //and return any value }, getNews : {   // we can redefine the target, transport, and envelope for specific services   target: ”/newsSearch”,   transport: ”GET”,   envelope: ”URL”,   parameters:[ { name: ”query”, type: ”string”, optional: false, default: ”” } ],   returns:{type:”array”} } }
But that’s not even a standard yet
WADL Example <application xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance      xsi:schemaLocation=http://research.sun.com/wadl/2006/10 wadl.xsd      xmlns:xsd=http://www.w3.org/2001/XMLSchema      xmlns:ex=http://www.example.org/types      xmlns=http://research.sun.com/wadl/2006/10>      <grammars>        <include href=ticker.xsd/>      </grammars>…
WADL Example <resources base=http://www.example.org/services/>         <resource path=getStockQuote>            <method name=GET>                 <request>                   <paramname=symbol style=query type=xsd:string/>                 </request>                <response>                   <representation mediaType=application/xml                        element=ex:quoteResponse/>                    <fault status=400 mediaType=application/xml                        element=ex:error/>                 </response>           </method>        </resource>    <! many other URIs>     </resources></application>
Looks a bit better, but it’s not widely adopted. So what do we do?
Service Discovery - Summery Use whatever your platform allows you (WSDL  for .NET, WADL  for JAVA and SMD for Dojo) Don’t allow service discovery – this may happen if:  You intend the web service to be used only internally. You are not using a tool to generate a proxy. You intend the web service to always be on a fixed IP Allow gradual service discovery Each call will expose different operations that are available Occasionally adds an unnecessary  overhead Can be solved using a parameter in the request to turn off and on gradual discovery Only exposes a part of the service that is related to the call
Service Discovery – WS-Discovery Web Services Dynamic Discovery A multicast discovery protocol that allows to locate web services over local network Uses web services standards like SOAP
SOAP Simple Object Access Protocol Message model: Request Response Error Advantages: Type safe WCF support feels more natural More appropriate for event driven use cases Services are discoverable Can carry any kind of data Disadvantages: Verbose WSDL Heavy payload, especially over HTTP Does not fit for streaming HTTP already knows how to handle requests/responses Accessing from a non-WCF client is nearly impossible Uses XML for the envelope, which makes the possibility to send any kind of data pretty much obsolete Conclusion Major pain in the ass
SOAP Example SOAP Request POST /InStock HTTP/1.1Host: www.example.orgContent-Type: application/soap+xml; charset=utf-8Content-Length: nnn<?xml version=”1.0”?><soap:Envelopexmlns:soap=”http://www.w3.org/2001/12/soap-envelope” soap:encodingStyle=”http://www.w3.org/2001/12/soap-encoding”><soap:Bodyxmlns:m=”http://www.example.org/stock”>  		<m:GetStockPrice>    			<m:StockName>IBM</m:StockName>  		</m:GetStockPrice>	</soap:Body></soap:Envelope>
SOAP Example SOAP Response HTTP/1.1 200 OKContent-Type: application/soap+xml; charset=utf-8Content-Length: nnn<?xml version=”1.0”?><soap:Envelopexmlns:soap=”http://www.w3.org/2001/12/soap-envelope” soap:encodingStyle=”http://www.w3.org/2001/12/soap-encoding”>	<soap:Bodyxmlns:m=”http://www.example.org/stock”>  		<m:GetStockPriceResponse>    			<m:Price>34.5</m:Price>  	</m:GetStockPriceResponse>	</soap:Body></soap:Envelope>
Oh dear, take this abomination away
REST Representational State Transfer Constrains Stateless Uniform Interface Layered System Cacheable Code On Demand (Optional) Guiding principles Identification of resources Manipulation of resources through these representations Self-descriptive messages Hypermedia As The Engine Of Application State (HATEOAS)
REST is an architecture, not a standard. This means we relay on whatever application protocol we have to use.
REST is not bound to HTTP but feels natural with HTTP
REST – Web Services A RESTful web service is implemented over HTTP URI – Unique Resource Identifier Provides unified interface to access resources. /Foos/ - A collection of resources /Foos/[Identifier]/ - An object instance inside a collection Uses HTTP Verbs GET Used to get content, no side effects are guaranteed POST Used to update content PUT Used to create/replace content DELETE Used to delete content OPTIONS HEAD Discoverable through OPTIONS and HEAD Verbs Allows request to refer to different representation through MIME-types Responds with HTTP Status Codes
Hands On – A Simple RESTful Web Service using ASP.NET MVC We’re going to write a simple blog application Why ASP.NET MVC? Easy to implement Appropriate for small services What are our entities? A Post A Tag A Comment A User Both tags and comments entities are sub-entities of a post Both posts and comments entities are sub-entities of a user
Hands On – A Simple RESTful Web Service using ASP.NET MVC The URI Scheme: To represent a resource collection of posts: /Posts/ To represent a specific post resource: /Posts/[id]/ To represent a resource collection of comments of a specific post resource: /Posts/[id]/Comments/ To represent a specific comment resource of a specific post resource: /Posts/[id]/Comments/[commentId] Well, you got the idea, right? How to implement: Go to your Global.asax file Define the routes Use constrains to avoid routes clashes Use constrains to define allowed HTTP Verbs
Hands On – A Simple RESTful Web Service using ASP.NET MVC Implementing the URI Scheme: publicstaticvoidRegisterRoutes(RouteCollection routes) {  // … routes.MapRoute(”DeleteComment”, ”Comments/{commentId}/”, new { controller = ”Comments”, action = ”Delete” }, new { commentId = @”+”, httpMethod = newHttpMethodConstraint(”DELETE”) }); routes.MapRoute(”EditComment”, ”Comments/{commentId}/”, new { controller = ”Comments”, action = ”Edit” }, new { commentId = @”+”, httpMethod = newHttpMethodConstraint(”PUT”) });    routes.MapRoute(”AddPostComment”, ”Posts/{postId}/Comments/”, new { controller = ”Comments”, action = ”Add” }, new { postId = @”+”, httpMethod = newHttpMethodConstraint(”POST”) });  routes.MapRoute(”PostComment”, ”Posts/{postId}/Comments/{commentId}/”, new { controller = ”Comments”, action = ”PostComment” }, new { postId = @”+”, commentId = @”+”, httpMethod = newHttpMethodConstraint(”GET”) });  routes.MapRoute(”PostComments”, ”Posts/{postId}/Comments/”, new { controller = ”Comments”, action = ”PostComments” }, new { postId = @”+”, httpMethod = newHttpMethodConstraint(”GET”) }); routes.MapRoute(”Comment”, ”Comments/{commentId}”, new { controller = ”Comments”, action = ”Comment” }, new { commentId = @”+”, httpMethod = newHttpMethodConstraint(”GET”) });  routes.MapRoute(”UserComments”, ”Users/{user}/Comments/”, new { controller = ”Comments”, action = ”UserComments” }, new { user = @”^[a-zA-Z0-9_]*$”, httpMethod = newHttpMethodConstraint(”GET”) });  routes.MapRoute(”UserComment”, ”Users/{user}/Comments/{commentId}/”,  new { controller = ”Comments”, action = ”UserComment” },  		  new { user = @”^[a-zA-Z0-9_]*$”, httpMethod = newHttpMethodConstraint(”GET”) }); // …}
Hands On – A Simple RESTful Web Service using ASP.NET MVC The URI Scheme - Explained: Defines a route that maps to an action that allows to delete a comment commentId is limited to integral values (for more information, read about Regular Expressions) You can reach to this action only by a DELETE request publicstaticvoidRegisterRoutes(RouteCollection routes) {  // … routes.MapRoute(”DeleteComment”, ”Comments/{commentId}/”, new { controller = ”Comments”, action = ”Delete” }, new { commentId = @”+”, httpMethod = newHttpMethodConstraint(”DELETE”) }); // …}
Hands On – A Simple RESTful Web Service using ASP.NET MVC The URI Scheme - Explained: Defines a route that maps to an action that allows to edit a comment commentId is limited to integral values You can reach to this action only by a PUT request Why are we using PUT instead of POST? The Comments/{commentId}/ URI refers to a specific item in a collection, since we are not sending only what is updated in our request we prefer to replace the resource instead of updating it publicstaticvoidRegisterRoutes(RouteCollection routes) {  // … routes.MapRoute(”EditComment”, ”Comments/{commentId}/”, new { controller = ”Comments”, action = ”Edit” }, new { commentId = @”+”, httpMethod = newHttpMethodConstraint(”PUT”) });  // …}
Hands On – A Simple RESTful Web Service using ASP.NET MVC The URI Scheme - Explained: Defines a route that maps to an action that allows to add a comment to a post postId is limited to integral values You can reach to this action only by a POST request Why are we using POST instead of PUT? The Posts/{postId}/Comments/ URI refers to a collection, PUT will replace all of our existing comments with a new one POST only updates a resource, so a new comment is added to our existing comments collection publicstaticvoidRegisterRoutes(RouteCollection routes) {  // … routes.MapRoute(”AddPostComment”, ”Posts/{postId}/Comments/”, new { controller = ”Comments”, action = ”Add” }, new { postId = @”+”, httpMethod = newHttpMethodConstraint(”POST”) });  // …}
Hands On – A Simple RESTful Web Service using ASP.NET MVC The URI Scheme - Explained: Those are the routes we are familiar with, the ones that use GET requests and most of the time return HTML In this example, this route maps to an action that allows us to access a specific comment on a post publicstaticvoidRegisterRoutes(RouteCollection routes) {  // …  routes.MapRoute(”PostComment”, ”Posts/{postId}/Comments/{commentId}/”, new { controller = ”Comments”, action = ”PostComment” }, new { postId = @”+”, commentId = @”+”, httpMethod = newHttpMethodConstraint(”GET”) }); // …}
Hands On – A Simple RESTful Web Service using ASP.NET MVC The comments controller: Now that our routes are defined we know what actions we need to implement All actions should use valid HTTP Status Codes All actions must be able to represent themselves in different formats (JSON, XML, HTML, RSS etc.) How to implement: Create a new controller called CommentsController Follow your routing scheme and create the needed actions Create a new action result decorator that allows you to select the HTTP Status code Use attributes to define allowed content types and HTTP Verbs
Hands On – A Simple RESTful Web Service using ASP.NET MVC Implementing the comments controller: publicclassCommentsController : Controller {         // …        [AcceptVerbs(HttpVerbs.Delete)] // Or [HttpDelete] if you are using MVC 2 and above publicActionResult Delete(intcommentId)         {             	// Delete operation occurs here returnnewHttpResponseCodeActionResultDecorator(204); // 204 No content }         [AcceptVerbs(HttpVerbs.Post)] // Or [HttpPost] if you are using MVC 2 and above publicActionResult Add(intpostId)         { 	        // Create a new comment that belongs to a post with a post Id of postIdreturnJson(new {CommentId = newCommentId}) ;         }         [AcceptVerbs(HttpVerbs.Put)] // Or [HttpPut] if you are using MVC 2 and above publicActionResult Add(intcommentId)         {            	// Create a new comment that belongs to a post with a post Id of postIdreturnnewHttpResponseCodeActionResultDecorator(201, Json(new {CommentId = newCommentId}) ); // 201 - Created }         // …}
Hands On – A Simple RESTful Web Service using ASP.NET MVC Implementing the HttpResponseCodeActionResultDecorator: publicclassHttpResponseCodeActionResultDecorator : ActionResult{         privatereadonlyintstatusCode;         privatereadonlyActionResultactionResult;         publicHttpResponseCodeActionResultDecorator(intstatusCode)         {             this.statusCode = statusCode;         }         publicHttpResponseCodeActionResultDecorator(intstatusCode, ActionResultactionResult)             : this(statusCode)         {             this.actionResult = actionResult;         }         publicoverridevoidExecuteResult(ControllerContext context)         {             context.HttpContext.Response.StatusCode = statusCode; if(actionResult != null)  	            actionResult.ExecuteResult(context);         } }
Hands On – A Simple RESTful Web Service using ASP.NET MVC Resources with multiple representations: Our list of posts should be representable through RSS and Atom feeds but also display them as HTML. An HTTP request containing an Accept header with a value other than application/rss+xml, application/atom+xml, text/html or application/xhtml+xml will return the HTTP response code “406 Not Acceptable”. The implementation is not trivial An example of an implementation can be seen here: http://aleembawany.com/2009/03/27/aspnet-mvc-create-easy-rest-api-with-json-and-xmlhowever it does not conform to HTTP due to the fact that it will either return 404 or the default view. How to implement: Create an ActionResult class that inspects the request’s Accept header and executes the requested ActionResult or return 406 Not Acceptable
Hands On – A Simple RESTful Web Service using ASP.NET MVC Implementing the AcceptTypeResult: publicclassAcceptTypeResult : ActionResult{         privatereadonlyint?successStatusCode; 	private readonly object result;         publicAcceptTypeResult(objectresult)         {            this.result = result;        }         publicAcceptTypeResult(intsuccessStatusCode, object result)          : this(result)         {            this.successStatusCode = successStatusCode;        }        publicoverridevoidExecuteResult(ControllerContext context)         { var request = context.HttpContext.Request;             context.HttpContext.Response.StatusCode = successStatusCode ?? 200; if (request.AcceptTypes.Contains(“application/rss+xml”)) Rss(result).ExecuteResult(context); else if (request.AcceptTypes.Contains(“application/atom+xml”)) Atom(result).ExecuteResult(context); else if (request.AcceptTypes.Contains(“application/xhtml+xml”) || request.AcceptTypes.Contains(“text/html”)) View(result).ExecuteResult(context); else             context.HttpContext.Response.StatusCode= 406;        } }
Bibliography http://www.infoq.com/articles/webber-rest-workflow http://www.infoq.com/articles/mark-baker-hypermedia http://barelyenough.org/blog/2007/05/hypermedia-as-the-engine-of-application-state/ http://third-bit.com/blog/archives/1746.html http://www.learnxpress.com/create-restful-wcf-service-api-step-by-step-guide.html http://www.infoq.com/articles/rest-soap-when-to-use-each http://www.prescod.net/rest/ http://www.prescod.net/rest/rest_vs_soap_overview/ http://www.devx.com/DevX/Article/8155 http://tomayko.com/writings/rest-to-my-wife http://en.wikipedia.org/wiki/Representational_State_Transfer http://en.wikipedia.org/wiki/HATEOAS http://en.wikipedia.org/wiki/SOAP http://en.wikipedia.org/wiki/SOA http://en.wikipedia.org/wiki/Web_Application_Description_Language http://en.wikipedia.org/wiki/WSDL http://en.wikipedia.org/wiki/JSON-RPC http://en.wikipedia.org/wiki/XML-RPC http://www.sitepen.com/blog/2008/03/19/pluggable-web-services-with-smd/
For further reading http://jcalcote.wordpress.com/2009/08/10/restful-authentication/ http://jcalcote.wordpress.com/2009/08/06/restful-transactions/ http://www.artima.com/lejava/articles/why_put_and_delete.html http://www.markbaker.ca/2002/08/HowContainersWork/ http://www.w3.org/Protocols/rfc2616/rfc2616.html http://www.elharo.com/blog/software-development/web-development/2005/12/08/post-vs-put/ http://blog.whatfettle.com/2006/08/14/so-which-crud-operation-is-http-post/ http://cafe.elharo.com/web/why-rest-failed/ http://en.wikipedia.org/wiki/Windows_Communication_Foundation
Thank you for listening!

Más contenido relacionado

La actualidad más candente

OSI model (7 LAYER )
OSI model (7 LAYER )OSI model (7 LAYER )
OSI model (7 LAYER )AAKASH S
 
Cisco Packet Tracer Overview 20 Jul09
Cisco Packet Tracer Overview 20 Jul09Cisco Packet Tracer Overview 20 Jul09
Cisco Packet Tracer Overview 20 Jul09Tumennast Erdenebold
 
Network resources
Network resourcesNetwork resources
Network resourcesRohit Kumar
 
CCNAv5 - S1: Chapter 7 - Transport Layer
CCNAv5 - S1: Chapter 7 - Transport LayerCCNAv5 - S1: Chapter 7 - Transport Layer
CCNAv5 - S1: Chapter 7 - Transport LayerVuz Dở Hơi
 
TCP/IP Presentation lab encapsulation and de-capsulation Nick Raston 2143803
TCP/IP Presentation lab encapsulation and de-capsulation Nick Raston 2143803TCP/IP Presentation lab encapsulation and de-capsulation Nick Raston 2143803
TCP/IP Presentation lab encapsulation and de-capsulation Nick Raston 2143803ArtistMuso
 
Osi model vs TCP/IP
Osi model vs TCP/IPOsi model vs TCP/IP
Osi model vs TCP/IPMannu Khani
 
UML Diagrams- Unified Modeling Language Introduction
UML Diagrams- Unified Modeling Language IntroductionUML Diagrams- Unified Modeling Language Introduction
UML Diagrams- Unified Modeling Language IntroductionRamakant Soni
 
CCNAv5 - S1: Chapter 10 Application Layer
CCNAv5 - S1: Chapter 10 Application LayerCCNAv5 - S1: Chapter 10 Application Layer
CCNAv5 - S1: Chapter 10 Application LayerVuz Dở Hơi
 
Obj 10 capa 6 - presentacion
Obj 10   capa 6 - presentacionObj 10   capa 6 - presentacion
Obj 10 capa 6 - presentacionPedro Sánchez
 
Form Validation in JavaScript
Form Validation in JavaScriptForm Validation in JavaScript
Form Validation in JavaScriptRavi Bhadauria
 
Chapter 15 : routing concepts
Chapter 15 : routing conceptsChapter 15 : routing concepts
Chapter 15 : routing conceptsteknetir
 
TCP/IP Network ppt
TCP/IP Network pptTCP/IP Network ppt
TCP/IP Network pptextraganesh
 
Networking in java, Advanced programming
Networking in java, Advanced programmingNetworking in java, Advanced programming
Networking in java, Advanced programmingGera Paulos
 
Ppt for tranmission media
Ppt for tranmission mediaPpt for tranmission media
Ppt for tranmission mediaManish8976
 

La actualidad más candente (20)

OSI model (7 LAYER )
OSI model (7 LAYER )OSI model (7 LAYER )
OSI model (7 LAYER )
 
Cisco Packet Tracer Overview 20 Jul09
Cisco Packet Tracer Overview 20 Jul09Cisco Packet Tracer Overview 20 Jul09
Cisco Packet Tracer Overview 20 Jul09
 
Network resources
Network resourcesNetwork resources
Network resources
 
CCNAv5 - S1: Chapter 7 - Transport Layer
CCNAv5 - S1: Chapter 7 - Transport LayerCCNAv5 - S1: Chapter 7 - Transport Layer
CCNAv5 - S1: Chapter 7 - Transport Layer
 
Network architecture
Network architectureNetwork architecture
Network architecture
 
TCP/IP Presentation lab encapsulation and de-capsulation Nick Raston 2143803
TCP/IP Presentation lab encapsulation and de-capsulation Nick Raston 2143803TCP/IP Presentation lab encapsulation and de-capsulation Nick Raston 2143803
TCP/IP Presentation lab encapsulation and de-capsulation Nick Raston 2143803
 
Osi model vs TCP/IP
Osi model vs TCP/IPOsi model vs TCP/IP
Osi model vs TCP/IP
 
Iso model
Iso modelIso model
Iso model
 
computer network OSI layer
computer network OSI layercomputer network OSI layer
computer network OSI layer
 
UML Diagrams- Unified Modeling Language Introduction
UML Diagrams- Unified Modeling Language IntroductionUML Diagrams- Unified Modeling Language Introduction
UML Diagrams- Unified Modeling Language Introduction
 
Notes Unit2.pptx
Notes Unit2.pptxNotes Unit2.pptx
Notes Unit2.pptx
 
CCNAv5 - S1: Chapter 10 Application Layer
CCNAv5 - S1: Chapter 10 Application LayerCCNAv5 - S1: Chapter 10 Application Layer
CCNAv5 - S1: Chapter 10 Application Layer
 
TCP/IP Introduction
TCP/IP IntroductionTCP/IP Introduction
TCP/IP Introduction
 
Obj 10 capa 6 - presentacion
Obj 10   capa 6 - presentacionObj 10   capa 6 - presentacion
Obj 10 capa 6 - presentacion
 
Form Validation in JavaScript
Form Validation in JavaScriptForm Validation in JavaScript
Form Validation in JavaScript
 
Framing Protocols
Framing ProtocolsFraming Protocols
Framing Protocols
 
Chapter 15 : routing concepts
Chapter 15 : routing conceptsChapter 15 : routing concepts
Chapter 15 : routing concepts
 
TCP/IP Network ppt
TCP/IP Network pptTCP/IP Network ppt
TCP/IP Network ppt
 
Networking in java, Advanced programming
Networking in java, Advanced programmingNetworking in java, Advanced programming
Networking in java, Advanced programming
 
Ppt for tranmission media
Ppt for tranmission mediaPpt for tranmission media
Ppt for tranmission media
 

Destacado

Services of internet
Services of internetServices of internet
Services of internetniraj singh
 
External Data Access with jQuery
External Data Access with jQueryExternal Data Access with jQuery
External Data Access with jQueryDoncho Minkov
 
SRS for Hospital Management System
SRS for Hospital Management SystemSRS for Hospital Management System
SRS for Hospital Management Systemkataria Arvind
 
Romansjosye
RomansjosyeRomansjosye
RomansjosyeFranJLte
 
The Forces of Disruptive Innovation for Startups
The Forces of Disruptive Innovation for StartupsThe Forces of Disruptive Innovation for Startups
The Forces of Disruptive Innovation for StartupsJa-Nae Duane
 
Collin powell 171
Collin powell 171Collin powell 171
Collin powell 171chhap
 
O'leary cell.ppt
O'leary cell.pptO'leary cell.ppt
O'leary cell.pptolearya
 
Katrin anacker tiaa_cref_submission
Katrin anacker tiaa_cref_submissionKatrin anacker tiaa_cref_submission
Katrin anacker tiaa_cref_submissionkanacker
 
San francisco native food
San francisco native foodSan francisco native food
San francisco native foodMari Cheung
 
Presentation re:new
Presentation re:newPresentation re:new
Presentation re:newPes Pse
 
Czy opłaciło się nam wejść do unii europejskiej
Czy opłaciło się nam wejść do unii europejskiejCzy opłaciło się nam wejść do unii europejskiej
Czy opłaciło się nam wejść do unii europejskiejsknsz
 
Ettkanne 13.sept.2013
Ettkanne 13.sept.2013Ettkanne 13.sept.2013
Ettkanne 13.sept.2013Margus Ots
 
Palmer warsaw school of economics presentation
Palmer warsaw school of economics presentationPalmer warsaw school of economics presentation
Palmer warsaw school of economics presentationsknsz
 
Why Average Response Time is not a right measure of your web application's pe...
Why Average Response Time is not a right measure of your web application's pe...Why Average Response Time is not a right measure of your web application's pe...
Why Average Response Time is not a right measure of your web application's pe...vodQA
 
Key note Manish and Deepa
Key note Manish and DeepaKey note Manish and Deepa
Key note Manish and DeepavodQA
 

Destacado (20)

Services of internet
Services of internetServices of internet
Services of internet
 
External Data Access with jQuery
External Data Access with jQueryExternal Data Access with jQuery
External Data Access with jQuery
 
SRS for Hospital Management System
SRS for Hospital Management SystemSRS for Hospital Management System
SRS for Hospital Management System
 
Romansjosye
RomansjosyeRomansjosye
Romansjosye
 
The Forces of Disruptive Innovation for Startups
The Forces of Disruptive Innovation for StartupsThe Forces of Disruptive Innovation for Startups
The Forces of Disruptive Innovation for Startups
 
Ldap a debian lenny pas a pas
Ldap a debian lenny pas a pasLdap a debian lenny pas a pas
Ldap a debian lenny pas a pas
 
Collin powell 171
Collin powell 171Collin powell 171
Collin powell 171
 
3 d tv
3 d tv3 d tv
3 d tv
 
O'leary cell.ppt
O'leary cell.pptO'leary cell.ppt
O'leary cell.ppt
 
Katrin anacker tiaa_cref_submission
Katrin anacker tiaa_cref_submissionKatrin anacker tiaa_cref_submission
Katrin anacker tiaa_cref_submission
 
San francisco native food
San francisco native foodSan francisco native food
San francisco native food
 
Presentation re:new
Presentation re:newPresentation re:new
Presentation re:new
 
Biggest loser
Biggest loserBiggest loser
Biggest loser
 
Czy opłaciło się nam wejść do unii europejskiej
Czy opłaciło się nam wejść do unii europejskiejCzy opłaciło się nam wejść do unii europejskiej
Czy opłaciło się nam wejść do unii europejskiej
 
Ettkanne 13.sept.2013
Ettkanne 13.sept.2013Ettkanne 13.sept.2013
Ettkanne 13.sept.2013
 
Palmer warsaw school of economics presentation
Palmer warsaw school of economics presentationPalmer warsaw school of economics presentation
Palmer warsaw school of economics presentation
 
งานฉันในอดีต
งานฉันในอดีตงานฉันในอดีต
งานฉันในอดีต
 
Why Average Response Time is not a right measure of your web application's pe...
Why Average Response Time is not a right measure of your web application's pe...Why Average Response Time is not a right measure of your web application's pe...
Why Average Response Time is not a right measure of your web application's pe...
 
Key note Manish and Deepa
Key note Manish and DeepaKey note Manish and Deepa
Key note Manish and Deepa
 
2012 Corporate Info
2012 Corporate Info2012 Corporate Info
2012 Corporate Info
 

Similar a Communication Protocols And Web Services

Similar a Communication Protocols And Web Services (20)

SOA and web services
SOA and web servicesSOA and web services
SOA and web services
 
Intro to web services
Intro to web servicesIntro to web services
Intro to web services
 
Web Services
Web ServicesWeb Services
Web Services
 
Web Services
Web ServicesWeb Services
Web Services
 
Restful web services
Restful web servicesRestful web services
Restful web services
 
Wsdl
WsdlWsdl
Wsdl
 
Switch to Backend 2023
Switch to Backend 2023Switch to Backend 2023
Switch to Backend 2023
 
jkljklj
jkljkljjkljklj
jkljklj
 
Bottom-Line Web Services
Bottom-Line Web ServicesBottom-Line Web Services
Bottom-Line Web Services
 
complete web service1.ppt
complete web service1.pptcomplete web service1.ppt
complete web service1.ppt
 
Internet protocalls & WCF/DReAM
Internet protocalls & WCF/DReAMInternet protocalls & WCF/DReAM
Internet protocalls & WCF/DReAM
 
Mobility Information Series - Webservice Architecture Comparison by RapidValue
Mobility Information Series - Webservice Architecture Comparison by RapidValueMobility Information Series - Webservice Architecture Comparison by RapidValue
Mobility Information Series - Webservice Architecture Comparison by RapidValue
 
Web services for developer
Web services for developerWeb services for developer
Web services for developer
 
Rest web service
Rest web serviceRest web service
Rest web service
 
Interoperable Web Services with JAX-WS and WSIT
Interoperable Web Services with JAX-WS and WSITInteroperable Web Services with JAX-WS and WSIT
Interoperable Web Services with JAX-WS and WSIT
 
REST vs WS-*: Myths Facts and Lies
REST vs WS-*: Myths Facts and LiesREST vs WS-*: Myths Facts and Lies
REST vs WS-*: Myths Facts and Lies
 
SOAP WEB TECHNOLOGIES
SOAP WEB TECHNOLOGIESSOAP WEB TECHNOLOGIES
SOAP WEB TECHNOLOGIES
 
Web services - REST and SOAP
Web services - REST and SOAPWeb services - REST and SOAP
Web services - REST and SOAP
 
RIA and Ajax
RIA and AjaxRIA and Ajax
RIA and Ajax
 
Semantic Web Servers
Semantic Web ServersSemantic Web Servers
Semantic Web Servers
 

Último

The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 

Último (20)

The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 

Communication Protocols And Web Services

  • 1. Communication Protocols and Web Services Created by Omer Katz, 2010 Omer Katz © Some Rights Reserved
  • 2. Structure of a standard networkingstack for the Web
  • 3. Common serialization formats JSON Natively supported within JavaScript Capable of referencing other records by convention Human readable format Lightweight Easy to parse Uses JSON-Schema to validate itself Key-Value based syntax XML JavaScript exposes a proprietary DOM API Human readable format for hierarchal data Hard to parse Consumes more memory than JSON Supports XSLT and XPath Uses XML-Schema or DTD to validate itself Markup based syntax
  • 4. What is a web service? A web service is typically an application programming interface (API) or Web API that is accessed via Hypertext Transfer Protocol (HTTP) and executed on a remote system, hosting the requested service. Web services do not provide the user with a GUI. Web services instead share business logic, data and processes through a programmatic interface across a network. Developers can then add the Web service to a GUI (such as a Web page or an executable program) to offer specific functionality to users.
  • 5. Web services communication protocols RPC XML-RPC HTTP Bound JSON-RPC SMD – Service Mapping Description JSONP Allows cross domain Ajax requests SOA SOAP XML Based Strongly typed WSDL dependant REST Stateless Cacheable Code On Demand Client and Server are unaware of each other’s state Layered System Uniform Interface Service may be described through SMD, WSDL, WADL or not at all
  • 6. What is RPC? Remote Procedure Call. Allows to access server-side/inter-process operations from a client through a well-defined protocol. Examples: COBRA, XML-RPC, JSON-RPC, DCOM, RMI Client is tightly coupled with the server
  • 7. JSON-RPC Request/Response model Request Notification Response Error Batch operations Advantages Lightweight JSON-Schemas can be extended to validate specific message Not bound to HTTP by the specification, but might be used with it Can be natively serialized from within JavaScript Service discovery can be achieved through SMD or WADL Disadvantages Procedural The web service's methods grow linearly with the number of client request types Not bound to a URI Conclusion Fits for low resources environment (embedded devices) Does not fit for rapidly growing web services Does not fit for web services operating on many entities unless the web service is an HTTP service
  • 8. JSON-RPC Examples A Notification: {     ”jsonrpc”: ”2.0”,     ”method”: ”update”,     ”params”: [1,2,3,4,5] }
  • 9. JSON-RPC Examples A Request {     ”jsonrpc”: ”2.0”,     ”method”: ”subtract”,     ”params”: {                    ”subtrahend”: 23,                    ”minuend”: 42                },     ”id”: 3 }
  • 10. JSON-RPC Examples An Error: { ”jsonrpc”: ”2.0”, ”error”: { ”code”: -32601, ”message”: ”Procedure not found.” }, ”id”: ”1” }
  • 11. JSON-RPC Examples Batch Request: [{ ”jsonrpc”: ”2.0”, ”method”: ”sum”, ”params”: [1,2,4], ”id”: ”1” },{ ”jsonrpc”: ”2.0”, ”method”: ”notify_hello”, ”params”: [7] },{ ”jsonrpc”: ”2.0”, ”method”: ”subtract”, ”params”: [42,23], ”id”: ”2” } ]
  • 12. JSON-RPC Examples Batch Response: [ {      ”jsonrpc”:”2.0”,      ”result”:7,      ”id”:”1” }, {      ”jsonrpc”:”2.0”,      ”result”:19,      ”id”:”2     },{      ”jsonrpc”:”2.0”,      ”error”:{         ”code”:-32601,         ”message”:” Procedure not found.”      },      ”id”:”5” }, ]
  • 13. XML-RPC Request/Response model Request Response Error Advantages Bound to a URI Can represent hierarchical data in a readable way XSLT & XPath Can be validated through XML-Schema or DTD Disadvantages Procedural The web service's methods grow linearly with the number of client request types Bound to HTTP Only appropriate for the web Hard to parse Heavy payload Consumes a lot of memory No bulk operations Conclusion Does not fit for rapidly growing web services Does not fit for embedded devices Fits to represent hierarchical data
  • 14. XML-RPC Examples Request: <?xml version=”1.0”?><methodCall> <methodName>examples.getStateName</methodName>            <params>                <param>                    <value>                        <i4>40</i4>                    </value>                </param>            </params></methodCall>
  • 15. XML-RPC Examples Response: <?xml version=”1.0”?>    <methodResponse>        <params><param>                <value>                    <string>South Dakota</string>                </value>            </param>        </params>    </methodResponse>
  • 16. XML-RPC Examples Error: <?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>
  • 17. What is SOA? Service Oriented Architecture. Allows to access server-side from a client through a well-defined protocol. Examples: SOAP, REST, SOAPjr Client does not have to be tightly coupled with the server. Unlike RPC based web services which usually are not discoverable there is a way to discover services in SOA based web service.
  • 18. Service Description Standards WSDL Web Services Description Language Well known Verbose Uses XML Not human readable Used by WCF Feels natural for SOAP services Endorsed by Microsoft WSDL 1.1 supports only GET and POST requests
  • 19. Service Description Standards - Continued WADL Web Application Description Language Not very well known A bit less verbose than WSDL Uses XML A bit more human readable Used by Java Feels natural for REST Services Endorsed by Sun Microsystems
  • 20. Service Description Standards - Continued SMD Service Mapping Description Working Draft status Less verbose Uses JSON Human readable Used by the Dojo Toolkit Not stable Endorsed by Sitepen and The Dojo Foundation
  • 21. WSDL Example <description> <types>    <schema>        <element name=”myMethod”>            <complexType>                <sequence>                    <element name=”x” type=”xsd:int”/>                    <element name=”y” type=”xsd:float”/>                </sequence>            </complexType>        </element>        <element name=”myMethodResponse”>            <complexType/>        </element>    </schema></types>…
  • 22. WSDL Example <message name=”myMethodRequest”>    <part name=”parameters” element=”myMethod”/></message><message name=”empty”>    <part name=”parameters” element=”myMethodResponse”/></message><portTypename=”PT”>    <operation name=”myMethod”>        <input message=”myMethodRequest”/>        <output message=”empty”/>    </operation></portType> Hold your horses, there’s more…
  • 23. WSDL Example <binding interface=”...”>        <!-- The binding of a protocol to an interface, same structure              as the interface element -->     </binding>     <service interface=”...”>        <!-- Defines the actual addresses of the bindings, as in 1.1,              but now ”ports” are called ”endpoints” -->        <endpoint binding=”...” address=”...”/>     </service></description> And it goes on and on… I actually tried to keep it short.
  • 24. Have I already mentioned that WSDL is verbose?
  • 25. SMD Example { target:”/jsonrpc”, // this defines the URL to connect for the services transport:”POST”, // We will use POST as the transport envelope:”JSON-RPC-1.2”, // We will use JSON-RPC SMDVersion:”2.0”, services: {   add : { // define a service to add two numbers   parameters: [     {name:”a”,type:”number”}, // define the two parameters     {name:”b”,type:”number”}],   returns:{”type”:”number”} }, foo : {   // nothing is required to be defined, all definitions are optional.   //This service has nothing defined so it can take any parameters   //and return any value }, getNews : {   // we can redefine the target, transport, and envelope for specific services   target: ”/newsSearch”,   transport: ”GET”,   envelope: ”URL”,   parameters:[ { name: ”query”, type: ”string”, optional: false, default: ”” } ],   returns:{type:”array”} } }
  • 26. But that’s not even a standard yet
  • 27. WADL Example <application xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance      xsi:schemaLocation=http://research.sun.com/wadl/2006/10 wadl.xsd      xmlns:xsd=http://www.w3.org/2001/XMLSchema      xmlns:ex=http://www.example.org/types      xmlns=http://research.sun.com/wadl/2006/10>      <grammars>        <include href=ticker.xsd/>      </grammars>…
  • 28. WADL Example <resources base=http://www.example.org/services/>         <resource path=getStockQuote>            <method name=GET>                 <request>                   <paramname=symbol style=query type=xsd:string/>                 </request>                <response>                   <representation mediaType=application/xml                        element=ex:quoteResponse/>                    <fault status=400 mediaType=application/xml                        element=ex:error/>                 </response>           </method>        </resource>    <! many other URIs>     </resources></application>
  • 29. Looks a bit better, but it’s not widely adopted. So what do we do?
  • 30. Service Discovery - Summery Use whatever your platform allows you (WSDL for .NET, WADL for JAVA and SMD for Dojo) Don’t allow service discovery – this may happen if: You intend the web service to be used only internally. You are not using a tool to generate a proxy. You intend the web service to always be on a fixed IP Allow gradual service discovery Each call will expose different operations that are available Occasionally adds an unnecessary overhead Can be solved using a parameter in the request to turn off and on gradual discovery Only exposes a part of the service that is related to the call
  • 31. Service Discovery – WS-Discovery Web Services Dynamic Discovery A multicast discovery protocol that allows to locate web services over local network Uses web services standards like SOAP
  • 32. SOAP Simple Object Access Protocol Message model: Request Response Error Advantages: Type safe WCF support feels more natural More appropriate for event driven use cases Services are discoverable Can carry any kind of data Disadvantages: Verbose WSDL Heavy payload, especially over HTTP Does not fit for streaming HTTP already knows how to handle requests/responses Accessing from a non-WCF client is nearly impossible Uses XML for the envelope, which makes the possibility to send any kind of data pretty much obsolete Conclusion Major pain in the ass
  • 33. SOAP Example SOAP Request POST /InStock HTTP/1.1Host: www.example.orgContent-Type: application/soap+xml; charset=utf-8Content-Length: nnn<?xml version=”1.0”?><soap:Envelopexmlns:soap=”http://www.w3.org/2001/12/soap-envelope” soap:encodingStyle=”http://www.w3.org/2001/12/soap-encoding”><soap:Bodyxmlns:m=”http://www.example.org/stock”>  <m:GetStockPrice>    <m:StockName>IBM</m:StockName>  </m:GetStockPrice> </soap:Body></soap:Envelope>
  • 34. SOAP Example SOAP Response HTTP/1.1 200 OKContent-Type: application/soap+xml; charset=utf-8Content-Length: nnn<?xml version=”1.0”?><soap:Envelopexmlns:soap=”http://www.w3.org/2001/12/soap-envelope” soap:encodingStyle=”http://www.w3.org/2001/12/soap-encoding”> <soap:Bodyxmlns:m=”http://www.example.org/stock”>  <m:GetStockPriceResponse>    <m:Price>34.5</m:Price>  </m:GetStockPriceResponse> </soap:Body></soap:Envelope>
  • 35. Oh dear, take this abomination away
  • 36. REST Representational State Transfer Constrains Stateless Uniform Interface Layered System Cacheable Code On Demand (Optional) Guiding principles Identification of resources Manipulation of resources through these representations Self-descriptive messages Hypermedia As The Engine Of Application State (HATEOAS)
  • 37. REST is an architecture, not a standard. This means we relay on whatever application protocol we have to use.
  • 38. REST is not bound to HTTP but feels natural with HTTP
  • 39. REST – Web Services A RESTful web service is implemented over HTTP URI – Unique Resource Identifier Provides unified interface to access resources. /Foos/ - A collection of resources /Foos/[Identifier]/ - An object instance inside a collection Uses HTTP Verbs GET Used to get content, no side effects are guaranteed POST Used to update content PUT Used to create/replace content DELETE Used to delete content OPTIONS HEAD Discoverable through OPTIONS and HEAD Verbs Allows request to refer to different representation through MIME-types Responds with HTTP Status Codes
  • 40. Hands On – A Simple RESTful Web Service using ASP.NET MVC We’re going to write a simple blog application Why ASP.NET MVC? Easy to implement Appropriate for small services What are our entities? A Post A Tag A Comment A User Both tags and comments entities are sub-entities of a post Both posts and comments entities are sub-entities of a user
  • 41. Hands On – A Simple RESTful Web Service using ASP.NET MVC The URI Scheme: To represent a resource collection of posts: /Posts/ To represent a specific post resource: /Posts/[id]/ To represent a resource collection of comments of a specific post resource: /Posts/[id]/Comments/ To represent a specific comment resource of a specific post resource: /Posts/[id]/Comments/[commentId] Well, you got the idea, right? How to implement: Go to your Global.asax file Define the routes Use constrains to avoid routes clashes Use constrains to define allowed HTTP Verbs
  • 42. Hands On – A Simple RESTful Web Service using ASP.NET MVC Implementing the URI Scheme: publicstaticvoidRegisterRoutes(RouteCollection routes) { // … routes.MapRoute(”DeleteComment”, ”Comments/{commentId}/”, new { controller = ”Comments”, action = ”Delete” }, new { commentId = @”+”, httpMethod = newHttpMethodConstraint(”DELETE”) }); routes.MapRoute(”EditComment”, ”Comments/{commentId}/”, new { controller = ”Comments”, action = ”Edit” }, new { commentId = @”+”, httpMethod = newHttpMethodConstraint(”PUT”) });  routes.MapRoute(”AddPostComment”, ”Posts/{postId}/Comments/”, new { controller = ”Comments”, action = ”Add” }, new { postId = @”+”, httpMethod = newHttpMethodConstraint(”POST”) });  routes.MapRoute(”PostComment”, ”Posts/{postId}/Comments/{commentId}/”, new { controller = ”Comments”, action = ”PostComment” }, new { postId = @”+”, commentId = @”+”, httpMethod = newHttpMethodConstraint(”GET”) });  routes.MapRoute(”PostComments”, ”Posts/{postId}/Comments/”, new { controller = ”Comments”, action = ”PostComments” }, new { postId = @”+”, httpMethod = newHttpMethodConstraint(”GET”) }); routes.MapRoute(”Comment”, ”Comments/{commentId}”, new { controller = ”Comments”, action = ”Comment” }, new { commentId = @”+”, httpMethod = newHttpMethodConstraint(”GET”) });  routes.MapRoute(”UserComments”, ”Users/{user}/Comments/”, new { controller = ”Comments”, action = ”UserComments” }, new { user = @”^[a-zA-Z0-9_]*$”, httpMethod = newHttpMethodConstraint(”GET”) });  routes.MapRoute(”UserComment”, ”Users/{user}/Comments/{commentId}/”, new { controller = ”Comments”, action = ”UserComment” },   new { user = @”^[a-zA-Z0-9_]*$”, httpMethod = newHttpMethodConstraint(”GET”) }); // …}
  • 43. Hands On – A Simple RESTful Web Service using ASP.NET MVC The URI Scheme - Explained: Defines a route that maps to an action that allows to delete a comment commentId is limited to integral values (for more information, read about Regular Expressions) You can reach to this action only by a DELETE request publicstaticvoidRegisterRoutes(RouteCollection routes) { // … routes.MapRoute(”DeleteComment”, ”Comments/{commentId}/”, new { controller = ”Comments”, action = ”Delete” }, new { commentId = @”+”, httpMethod = newHttpMethodConstraint(”DELETE”) }); // …}
  • 44. Hands On – A Simple RESTful Web Service using ASP.NET MVC The URI Scheme - Explained: Defines a route that maps to an action that allows to edit a comment commentId is limited to integral values You can reach to this action only by a PUT request Why are we using PUT instead of POST? The Comments/{commentId}/ URI refers to a specific item in a collection, since we are not sending only what is updated in our request we prefer to replace the resource instead of updating it publicstaticvoidRegisterRoutes(RouteCollection routes) { // … routes.MapRoute(”EditComment”, ”Comments/{commentId}/”, new { controller = ”Comments”, action = ”Edit” }, new { commentId = @”+”, httpMethod = newHttpMethodConstraint(”PUT”) }); // …}
  • 45. Hands On – A Simple RESTful Web Service using ASP.NET MVC The URI Scheme - Explained: Defines a route that maps to an action that allows to add a comment to a post postId is limited to integral values You can reach to this action only by a POST request Why are we using POST instead of PUT? The Posts/{postId}/Comments/ URI refers to a collection, PUT will replace all of our existing comments with a new one POST only updates a resource, so a new comment is added to our existing comments collection publicstaticvoidRegisterRoutes(RouteCollection routes) { // … routes.MapRoute(”AddPostComment”, ”Posts/{postId}/Comments/”, new { controller = ”Comments”, action = ”Add” }, new { postId = @”+”, httpMethod = newHttpMethodConstraint(”POST”) }); // …}
  • 46. Hands On – A Simple RESTful Web Service using ASP.NET MVC The URI Scheme - Explained: Those are the routes we are familiar with, the ones that use GET requests and most of the time return HTML In this example, this route maps to an action that allows us to access a specific comment on a post publicstaticvoidRegisterRoutes(RouteCollection routes) { // …  routes.MapRoute(”PostComment”, ”Posts/{postId}/Comments/{commentId}/”, new { controller = ”Comments”, action = ”PostComment” }, new { postId = @”+”, commentId = @”+”, httpMethod = newHttpMethodConstraint(”GET”) }); // …}
  • 47. Hands On – A Simple RESTful Web Service using ASP.NET MVC The comments controller: Now that our routes are defined we know what actions we need to implement All actions should use valid HTTP Status Codes All actions must be able to represent themselves in different formats (JSON, XML, HTML, RSS etc.) How to implement: Create a new controller called CommentsController Follow your routing scheme and create the needed actions Create a new action result decorator that allows you to select the HTTP Status code Use attributes to define allowed content types and HTTP Verbs
  • 48. Hands On – A Simple RESTful Web Service using ASP.NET MVC Implementing the comments controller: publicclassCommentsController : Controller {         // …        [AcceptVerbs(HttpVerbs.Delete)] // Or [HttpDelete] if you are using MVC 2 and above publicActionResult Delete(intcommentId)         {              // Delete operation occurs here returnnewHttpResponseCodeActionResultDecorator(204); // 204 No content }         [AcceptVerbs(HttpVerbs.Post)] // Or [HttpPost] if you are using MVC 2 and above publicActionResult Add(intpostId)         {         // Create a new comment that belongs to a post with a post Id of postIdreturnJson(new {CommentId = newCommentId}) ;         }         [AcceptVerbs(HttpVerbs.Put)] // Or [HttpPut] if you are using MVC 2 and above publicActionResult Add(intcommentId)         {             // Create a new comment that belongs to a post with a post Id of postIdreturnnewHttpResponseCodeActionResultDecorator(201, Json(new {CommentId = newCommentId}) ); // 201 - Created }         // …}
  • 49. Hands On – A Simple RESTful Web Service using ASP.NET MVC Implementing the HttpResponseCodeActionResultDecorator: publicclassHttpResponseCodeActionResultDecorator : ActionResult{         privatereadonlyintstatusCode;         privatereadonlyActionResultactionResult;         publicHttpResponseCodeActionResultDecorator(intstatusCode)         {             this.statusCode = statusCode;         }         publicHttpResponseCodeActionResultDecorator(intstatusCode, ActionResultactionResult)             : this(statusCode)         {             this.actionResult = actionResult;         }         publicoverridevoidExecuteResult(ControllerContext context)         {             context.HttpContext.Response.StatusCode = statusCode; if(actionResult != null)             actionResult.ExecuteResult(context);         } }
  • 50. Hands On – A Simple RESTful Web Service using ASP.NET MVC Resources with multiple representations: Our list of posts should be representable through RSS and Atom feeds but also display them as HTML. An HTTP request containing an Accept header with a value other than application/rss+xml, application/atom+xml, text/html or application/xhtml+xml will return the HTTP response code “406 Not Acceptable”. The implementation is not trivial An example of an implementation can be seen here: http://aleembawany.com/2009/03/27/aspnet-mvc-create-easy-rest-api-with-json-and-xmlhowever it does not conform to HTTP due to the fact that it will either return 404 or the default view. How to implement: Create an ActionResult class that inspects the request’s Accept header and executes the requested ActionResult or return 406 Not Acceptable
  • 51. Hands On – A Simple RESTful Web Service using ASP.NET MVC Implementing the AcceptTypeResult: publicclassAcceptTypeResult : ActionResult{         privatereadonlyint?successStatusCode; private readonly object result;         publicAcceptTypeResult(objectresult)         {            this.result = result;        }         publicAcceptTypeResult(intsuccessStatusCode, object result) : this(result)         {            this.successStatusCode = successStatusCode;        }        publicoverridevoidExecuteResult(ControllerContext context)         { var request = context.HttpContext.Request;             context.HttpContext.Response.StatusCode = successStatusCode ?? 200; if (request.AcceptTypes.Contains(“application/rss+xml”)) Rss(result).ExecuteResult(context); else if (request.AcceptTypes.Contains(“application/atom+xml”)) Atom(result).ExecuteResult(context); else if (request.AcceptTypes.Contains(“application/xhtml+xml”) || request.AcceptTypes.Contains(“text/html”)) View(result).ExecuteResult(context); else             context.HttpContext.Response.StatusCode= 406;        } }
  • 52. Bibliography http://www.infoq.com/articles/webber-rest-workflow http://www.infoq.com/articles/mark-baker-hypermedia http://barelyenough.org/blog/2007/05/hypermedia-as-the-engine-of-application-state/ http://third-bit.com/blog/archives/1746.html http://www.learnxpress.com/create-restful-wcf-service-api-step-by-step-guide.html http://www.infoq.com/articles/rest-soap-when-to-use-each http://www.prescod.net/rest/ http://www.prescod.net/rest/rest_vs_soap_overview/ http://www.devx.com/DevX/Article/8155 http://tomayko.com/writings/rest-to-my-wife http://en.wikipedia.org/wiki/Representational_State_Transfer http://en.wikipedia.org/wiki/HATEOAS http://en.wikipedia.org/wiki/SOAP http://en.wikipedia.org/wiki/SOA http://en.wikipedia.org/wiki/Web_Application_Description_Language http://en.wikipedia.org/wiki/WSDL http://en.wikipedia.org/wiki/JSON-RPC http://en.wikipedia.org/wiki/XML-RPC http://www.sitepen.com/blog/2008/03/19/pluggable-web-services-with-smd/
  • 53. For further reading http://jcalcote.wordpress.com/2009/08/10/restful-authentication/ http://jcalcote.wordpress.com/2009/08/06/restful-transactions/ http://www.artima.com/lejava/articles/why_put_and_delete.html http://www.markbaker.ca/2002/08/HowContainersWork/ http://www.w3.org/Protocols/rfc2616/rfc2616.html http://www.elharo.com/blog/software-development/web-development/2005/12/08/post-vs-put/ http://blog.whatfettle.com/2006/08/14/so-which-crud-operation-is-http-post/ http://cafe.elharo.com/web/why-rest-failed/ http://en.wikipedia.org/wiki/Windows_Communication_Foundation
  • 54. Thank you for listening!