Top Banner
CS 415 N-Tier Application Development By Umair Ashraf July 6 ,2013 National University of Computer and Emerging Sciences Lecture # 9 Introduction to Web Services
22

CS 415 N-Tier Application Development By Umair Ashraf July 6,2013 National University of Computer and Emerging Sciences Lecture # 9 Introduction to Web.

Dec 23, 2015

Download

Documents

Whitney West
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CS 415 N-Tier Application Development By Umair Ashraf July 6,2013 National University of Computer and Emerging Sciences Lecture # 9 Introduction to Web.

CS 415 N-Tier Application Development

By Umair Ashraf

July 6 ,2013

National University of Computer and Emerging Sciences

Lecture # 9 Introduction to Web Services

Page 2: CS 415 N-Tier Application Development By Umair Ashraf July 6,2013 National University of Computer and Emerging Sciences Lecture # 9 Introduction to Web.

Agenda/Contents for Today’s Lecture

Introduction to Web Services Understanding Services SOAP Services REST Services Examples

Page 3: CS 415 N-Tier Application Development By Umair Ashraf July 6,2013 National University of Computer and Emerging Sciences Lecture # 9 Introduction to Web.

What is a web service ?

A Web Service is a standards-based, softwareentity, that accepts specially formatted

requests from othersoftware entities on remote machines via

vendor and transportneutral communication protocols, producing

application specificresponses    

Page 4: CS 415 N-Tier Application Development By Umair Ashraf July 6,2013 National University of Computer and Emerging Sciences Lecture # 9 Introduction to Web.

Benefits of Web Service• Loose Coupled DesignEach service exists independently of the other services thatmake up the application. Individual pieces of the applicationto be modified without impacting unrelated areas.• Ease of IntegrationData is isolated between applications . WebServices act as glue between these and enable easiercommunications within and across organizations.• Service ReuseTakes code reuse a step further. A specific function within thedomain is only ever coded once and used over and over againby consuming applications.

Page 5: CS 415 N-Tier Application Development By Umair Ashraf July 6,2013 National University of Computer and Emerging Sciences Lecture # 9 Introduction to Web.

Web Services ArchitectureThe simplest Web service system has two participants:• A service producer (provider)• A service consumer (requester).The provider presents the interface and implementation of the service, and the requester uses the Web service

Page 6: CS 415 N-Tier Application Development By Umair Ashraf July 6,2013 National University of Computer and Emerging Sciences Lecture # 9 Introduction to Web.

Web Services Architecture (SOA)

A more sophisticated system: A registry, acts as a broker for Web services. A provider, can publish services to the registry A consumer, can then discover services in the registry

Page 7: CS 415 N-Tier Application Development By Umair Ashraf July 6,2013 National University of Computer and Emerging Sciences Lecture # 9 Introduction to Web.

SOAP (Simple Object Access Protocol) Web Service SOAP is a simple XML-based protocol to let

applications exchange information over HTTP.

SOAP is a industry accepted W3C specification that uses standards based technologies (XML for data description and HTTP for transport) to encode and transmit application data.

Page 8: CS 415 N-Tier Application Development By Umair Ashraf July 6,2013 National University of Computer and Emerging Sciences Lecture # 9 Introduction to Web.

SOAP Message Structure The root element of a SOAP message is the Envelope element. It contains an optional Header element and the required Body Elements called Faults can be used to describe exceptional situations. It can contain optional Attachments in MIME encoding for exchanging binary data.

Page 9: CS 415 N-Tier Application Development By Umair Ashraf July 6,2013 National University of Computer and Emerging Sciences Lecture # 9 Introduction to Web.

SOAP Example <?xml version="1.0" encoding="UTF-8"?> <soap:Envelope soap:encodingStyle="http://soap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-inst"> <soap:Header> <!-- Transactions, priorites, etc. --> </soap:Header> <soap:Body> <!-- Some content --> </soap:Body> </soap:Envelope>

Page 10: CS 415 N-Tier Application Development By Umair Ashraf July 6,2013 National University of Computer and Emerging Sciences Lecture # 9 Introduction to Web.

SOAP Message Transmission The SOAP Message Transmission involves three main roles: The SOAP Sender creates and sends a SOAP Message to an ultimate SOAP Receiver. One or more optional SOAP Intermediaries can be positioned to intercept messages between the the sender

and the receiver. They can perform filtering, logging, catching

etc. The SOAP sender’s intended destination is called the Ultimate SOAP Receiver.

Page 11: CS 415 N-Tier Application Development By Umair Ashraf July 6,2013 National University of Computer and Emerging Sciences Lecture # 9 Introduction to Web.

SOAP Request ExamplePOST /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:Body xmlns:m="http://www.example.org/stock">  <m:GetStockPrice>    <m:StockName>IBM</m:StockName>  </m:GetStockPrice></soap:Body>

</soap:Envelope>

Page 12: CS 415 N-Tier Application Development By Umair Ashraf July 6,2013 National University of Computer and Emerging Sciences Lecture # 9 Introduction to Web.

SOAP ResponseHTTP/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:Body xmlns:m="http://www.example.org/stock">  <m:GetStockPriceResponse>    <m:Price>34.5</m:Price>  </m:GetStockPriceResponse></soap:Body>

</soap:Envelope>

Page 13: CS 415 N-Tier Application Development By Umair Ashraf July 6,2013 National University of Computer and Emerging Sciences Lecture # 9 Introduction to Web.

SOAP Demo

ASP.NET Web Service DEMO project step by step creation and Working Example in Class

Page 14: CS 415 N-Tier Application Development By Umair Ashraf July 6,2013 National University of Computer and Emerging Sciences Lecture # 9 Introduction to Web.

Introduction to REST

Representational state transfer (REST) is a style of software architecture for distributed systems such as the World Wide Web

Page 15: CS 415 N-Tier Application Development By Umair Ashraf July 6,2013 National University of Computer and Emerging Sciences Lecture # 9 Introduction to Web.

REST Web ServicesREST defines a set of architectural principles by which you can design Web services that focus on a system's resources, including how resource states are addressed and transferred over HTTP by a wide range of clients written in different languages. If measured by the number of Web services that use it, REST has emerged in the last few years alone as a predominant Web service design model. In fact, REST has had such a large impact on the Web that it has mostly displaced SOAP- and WSDL-based interface design because it's a considerably simpler style to use.

Page 16: CS 415 N-Tier Application Development By Umair Ashraf July 6,2013 National University of Computer and Emerging Sciences Lecture # 9 Introduction to Web.

Fundamental Characteristics of REST

Client Server Separation of Concerns is a principle where the user interface is

separated from data storage. This leads to the portability of the user interface across multiple platforms and improves scalability by simplifying server components.

Stateless Each request to the server should contain all the information

required to understand and complete the request. Cacheable The data within a response to a request should be cacheable/

non-cacheable to be used by client at another point of time. This might improve the performance and reduce network traffic.

Layered System Intermediary servers like Proxy servers or Cache servers can be

used to improve performance or introduce security.

Page 17: CS 415 N-Tier Application Development By Umair Ashraf July 6,2013 National University of Computer and Emerging Sciences Lecture # 9 Introduction to Web.

Fundamental Characteristics of REST Uniform Interface A uniform interface (like HTTP GET, POST, DELETE, PUT) is to be used

to access a resource. A RESTful Web Service is a collection of the following: URI Uniform Resource Identifier - This is a unique way of identifying

resources on the network. Every resource on the web is given a unique identifier - a universal identifier (example, URL). All web browsers, servers, applications understand this identifier, which makes it easy to connect and exchange information between one another without any issues.

MIME Type Can be XML, HTML, and JSON. HTTP Methods HTTP forms a standard way to communicate with resources on the

web. GET, PUT, DELETE, POST are some of the common methods to access a resource.

Page 18: CS 415 N-Tier Application Development By Umair Ashraf July 6,2013 National University of Computer and Emerging Sciences Lecture # 9 Introduction to Web.

SOAP Versus REST Request Using Web Services and SOAP, the request would look something like this:

<?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:body pb="http://www.acme.com/phonebook"> <pb:GetUserDetails> <pb:UserID>12345</pb:UserID> </pb:GetUserDetails> </soap:Body></soap:Envelope>(The details are not important; this is just an example.) The entire shebang now has to be sent (using an HTTP POST request) to the server. The result is probably an XML file, but it will be embedded, as the "payload", inside a SOAP response envelope.

And with REST? The query will probably look like this:

http://www.acme.com/phonebook/UserDetails/12345

Page 19: CS 415 N-Tier Application Development By Umair Ashraf July 6,2013 National University of Computer and Emerging Sciences Lecture # 9 Introduction to Web.

REST Response<parts-list> <part id="3322"> <name>ACME Boomerang</name> <desc> Used by Coyote in <i>Zoom at the Top</i>, 1962 </desc> <price currency="usd" quantity="1">17.32</price> <uri>http://www.acme.com/parts/3322</uri> </part> <part id="783"> <name>ACME Dehydrated Boulders</name> <desc> Used by Coyote in <i>Scrambled Aches</i>, 1957 </desc> <price currency="usd" quantity="pack">19.95</price> <uri>http://www.acme.com/parts/783</uri> </part></parts-list>

Page 20: CS 415 N-Tier Application Development By Umair Ashraf July 6,2013 National University of Computer and Emerging Sciences Lecture # 9 Introduction to Web.

Fundamental Characteristics of REST GET Helps to request a specific representation of

the resource. PUT Updates a resource with a specific

representation. DELETE Deletes a specified resource. POST Creates a new resource

Page 21: CS 415 N-Tier Application Development By Umair Ashraf July 6,2013 National University of Computer and Emerging Sciences Lecture # 9 Introduction to Web.

REST Web Service Implementation

DEMO in class

Page 22: CS 415 N-Tier Application Development By Umair Ashraf July 6,2013 National University of Computer and Emerging Sciences Lecture # 9 Introduction to Web.

Reference Materialhttp://www.w3schools.com/soap/http://msdn.microsoft.com/en-us/library/ms972326.aspxhttp://www.codeproject.com/Articles/337535/Understanding-the-Basics-of-Web-Service-in-ASP-NET

http://en.wikipedia.org/wiki/Representational_state_transferhttp://www.ibm.com/developerworks/webservices/library/ws-restful/http://rest.elkstein.org/2008/02/what-is-rest.htmlhttp://msdn.microsoft.com/en-us/library/dd203052.aspx