CS520 Web Programming Introduction to Web Services Chengyu Sun California State University, Los Angeles.

Slides:



Advertisements
Similar presentations
18 Copyright © 2005, Oracle. All rights reserved. Distributing Modular Applications: Introduction to Web Services.
Advertisements

REST Vs. SOAP.
31242/32549 Advanced Internet Programming Advanced Java Programming
Web Services Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission.
Web Service Ahmed Gamal Ahmed Nile University Bioinformatics Group
General introduction to Web services and an implementation example
SOAP.
1 Understanding Web Services Presented By: Woodas Lai.
RPC Robert Grimm New York University Remote Procedure Calls.
Web Services Darshan R. Kapadia Gregor von Laszewski 1http://grid.rit.edu.
Web Services Nasrullah. Motivation about web service There are number of programms over the internet that need to communicate with other programms over.
Presentation 7 part 2: SOAP & WSDL. Ingeniørhøjskolen i Århus Slide 2 Outline Building blocks in Web Services SOA SOAP WSDL (UDDI)
CS490T Advanced Tablet Platform Applications Network Programming Evolution.
Grid Computing, B. Wilkinson, 20043a.1 WEB SERVICES Introduction.
Introduction to Remote Method Invocation (RMI)
Web Service What exactly are Web Services? To put it quite simply, they are yet another distributed computing technology (like CORBA, RMI, EJB, etc.).
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 Michael Smith Alex Feldman. What is a Web Service? A Web service is a message-oriented software system designed to support inter-operable.
Processing of structured documents Spring 2003, Part 6 Helena Ahonen-Myka.
Introduction SOAP History Technical Architecture SOAP in Industry Summary References.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
Avro Apache Course: Distributed class Student ID: AM Name: Azzaya Galbazar
T Network Application Frameworks and XML Web Services and WSDL Sasu Tarkoma Based on slides by Pekka Nikander.
Prepared By : Monika Darji Web Services using REST & JAX-WS.
1 HKU CSIS DB Seminar: HKU CSIS DB Seminar: Web Services Oriented Data Processing and Integration Speaker: Eric Lo.
CSCI 6962: Server-side Design and Programming Web Services.
CS 390- Unix Programming Environment CS 390 Unix Programming Environment Topics to be covered: Distributed Computing Fundamentals.
Lecture 15 Introduction to Web Services Web Service Applications.
Web Services Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
Web Services based e-Commerce System Sandy Liu Jodrey School of Computer Science Acadia University July, 2002.
Web Services. ASP.NET Web Services  Goals of ASP.NET Web services:  To enable cross-platform, cross- business computing  Great for “service” based.
1 EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction.
Distributed Programming CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Copyright © 2013 Curt Hill SOAP Protocol for exchanging data and Enabling Web Services.
1 Seminar on Service Oriented Architecture Principles of REST.
XML and Web Services (II/2546)
1 Engineering Web Based Legacy Systems By Kanchana Eramudugoda Distributed Computing – CS843.
S imple O bject A ccess P rotocol Karthikeyan Chandrasekaran & Nandakumar Padmanabhan.
Kemal Baykal Rasim Ismayilov
S O A P ‘the protocol formerly known as Simple Object Access Protocol’ Team Pluto Bonnie, Brandon, George, Hojun.
ASP.NET Web Services.  A unit of managed code installed under IIS that can be remotely invoked using HTTP.
Advanced Web Technologies Lecture #4 By: Faraz Ahmed.
An Introduction to Web Services Web Services using Java / Session 1 / 2 of 21 Objectives Discuss distributed computing Explain web services and their.
RESTful Web Services What is RESTful?
Web Services An Introduction Copyright © Curt Hill.
Web Technologies Lecture 10 Web services. From W3C – A software system designed to support interoperable machine-to-machine interaction over a network.
Intro to Web Services Dr. John P. Abraham UTPA. What are Web Services? Applications execute across multiple computers on a network.  The machine on which.
.NET Mobile Application Development XML Web Services.
Net-centric Computing Web Services. Lecture Outline  What is Web Service  Web Service Architecture  Creating and using Java Web Services  Apache Axis.
The Java API for XML-Based Web Services. A Web Service example in Java SOAP-awareServlet (e.g. Apache Axis2) SOAP-awareServlet Any class processing the.
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 9 Web Services: JAX-RPC,
CS3220 Web and Internet Programming RESTful Web Service
CS520 Web Programming Introduction to Web Services
Introduction to Web Services
CS5220 Advanced Topics in Web Programming Web Services
Sabri Kızanlık Ural Emekçi
WEB SERVICES.
T Network Application Frameworks and XML Web Services and WSDL Sasu Tarkoma Based on slides by Pekka Nikander.
Unit – 5 JAVA Web Services
GF and RS, Dept. of CS, Mangalore University
WEB API.
Chapter 9 Web Services: JAX-RPC, WSDL, XML Schema, and SOAP
Creating a Distributed System with Remote Procedure Calls and Web Services Ch.5 B.Ramamurthy 2/17/2019 B.Ramamurthy.
CS5220 Advanced Topics in Web Programming Web Services
WebServices Using JAX-RPC
Chengyu Sun California State University, Los Angeles
Distributed System using Web Services
Distributed System using Web Services
Chengyu Sun California State University, Los Angeles
Presentation transcript:

CS520 Web Programming Introduction to Web Services Chengyu Sun California State University, Los Angeles

Client-Server Architecture ClientServer processing data result

Client-Server Example ClientServer processing username password first_name last_name age user not found or

Socket Programming – Client Tedious networking code Application specific data exchange protocols create socket write string to socket read string from socket if( “user not found” ) return null; else return new User( read string from socket read integer from socket ) close socket

Client-Server Interaction as Function Calls Client Server User user = auth(username, password); User auth(String u, String p) { … return user; } Automatically translate function calls to network operations Encode and decode parameters and return values Send and receive data between the client and the server

RPC and RMI Remote Procedure Call (RPC) C Remote Method Invocation (RMI) Java

RMI – Server Create a service interface Remote interface Declares the methods to be remotely invoked Create a service implementation Remote object Implements the methods to be remotely invoked Register the service with a RMI registry so a client can find and use this service

RMI – Client Connect to the RMI registry Look up the service by name Invoke the method

RMI Example: AuthService Shared by both server and client AuthService User Server AuthServiceImpl AuthServiceStartup Client AuthServiceClient Why does User have to implement the Serializable interface? What exactly does registry.lookup() return?

How RMI Works Registry Remote Object Client code 1. Lookup Stub (Proxy) 2. Stub (proxy) 0. Register 3. Method invocation 5. Result 4. Parameters 6. Return result Client Server

Cross Platform RPC The client and the server use different languages and/or platforms ClientServer C/C++ Java C# Python PHP … C/C++ Java C# Python PHP … Windows Linux … Windows Linux … ?? How do we define service interface??

CORBA Common Object Request Broker Architecture Use Interface Definition Language (IDL) to describe service interface Provide mappings from IDL to other languages such as Java, C++, and so on. Service Implementation Service Interface in IDL Java C++ … ServerClient

IDL Example module bank { interface BankAccount { exception ACCOUNT_ERROR { long errcode; string message;}; long querybalance(in long acnum) raises (ACCOUNT_ERROR); string queryname(in long acnum) raises (ACCOUNT_ERROR); string queryaddress(in long acnum) raises (ACCOUNT_ERROR); void setbalance(in long acnum, in long balance) raises (ACCOUNT_ERROR); void setaddress(in long acnum, in string address) raises (ACCOUNT_ERROR); };

(Traditional) Web Services RPC over HTTP Client and server communicate using HTTP requests and responses Many different web service protocols Language support: single language vs. language independent Message encoding: binary vs. text Most widely used: SOAP

Metro A Java web service library backed by SUN/Oracle Implementation of the latest Java web service specifications Guaranteed interoperability with.NET Windows Communication Foundation (WCF) web services Easy to use

Other Java Web Service Libraries Apache Axis2 Apache CXF

Web Service Example: HashService Dependency: org.glasshfish.metro:webservi ces-rt web.xml sun-jaxws.xml

WSDL A language for describing web services Where the service is What the service does How to invoke the operations of the service Plays a role similar to IDF in CORBA

Sample WSDL Documents HashService Amazon ECS - erceService/AWSECommerceService.wsdl erceService/AWSECommerceService.wsdl

How Do We Describe an API interface Foo { … int bar( String, BigDecimal ) } interface name Method nameParametersReturn value Type

How Do We Describe an Web Service API Type Parameters Return value Method name Interface name WSDL

Web Service Example: Consume HashService Generate client side interface and stub from WSDL using Metro’s wsimport Write client code

SOAP Simple Object Access Protocol Client Web Service Client Server Web Service Implementation SOAP

A Sample SOAP Message <SOAP-ENV:Envelope xmlns:SOAP-ENV= xmlns:xsi= xmlns:xsd=" <ns1:doSpellingSuggestion xmlns:ns1="urn:GoogleSearch" SOAP-ENV:encodingStyle=" britney speers

A Sample SOAP RPC Response <SOAP-ENV:Envelope xmlns:SOAP-ENV= xmlns:xsi= xmlns:xsd=" <ns1:doSpellingSuggestionResponse xmlns:ns1="urn:GoogleSearch“ SOAP-ENV:encodingStyle=" britney spears

A Sample Fault Response <SOAP-ENV:Envelope xmlns:SOAP-ENV=" SOAP-ENV:encodingStyle=" SOAP-ENV:Client Client Error Invalid Currency 1234

SOAP Encoding Include all built-in data types of XML Schema Part 2: Datatypes xsi and xsd name spaces

SOAP Encoding Examples SOAP int a = 10; float x = ; String s = “SOAP”;

Compound Values and Other Rules References, default values, custom types, complex types, custom serialization … Ten

UDDI Universal Description Discovery and Integration A registry for web services A web API for publishing, retrieving, and managing information in the registry

UDDI Registries

Problems with SOAP Web Service Very complex Based on some very complex specifications Very difficult to create supporting libraries Virtually impossible to use without supporting libraries Not very efficient RESTful Web Services

A RESTful Web Service Get user with id=1: /service/user/1 1 John Doe Request XML ResponseorJSON Response { “id”: 1, “firstName”: “John”, “lastName”: “Doe”, “ ”: }

Is That Really A Web Service? Where is the method call? Why does it look like a web application? Why is it called RESTful?

Where Is The Method Call? Answer: it’s kind of a method call … User user = getUser( 1 ); HTTP request: /service/user/ 1 HTTP response The downside is that now it’s the client’s responsibility to turn an HTTP response into a “return value”, which is why the response is usually in XML or JSON format.

Why Does It Look Like A Web Application? Answer: it does, and it’s a good thing. Now all web technologies/languages can be used to create web services (and you don’t have to implement complex specifications like SOAP).

Why Is It Called RESTful? REpresentational State Transfer Introduced by Roy Fielding in his Ph.D. dissertation on network-base software architecture Describes the common characteristics of scalable, maintainable, and efficient distributed software systems

The REST Constraints Client and server Stateless Support caching Uniformly accessible Layered (Optional) support code-on-demand

RESTful Web Services Web applications for programs Generate responses in formats to be read by machines (i.e. XML and JSON) rather than by humans (i.e. HTML) Simulate how the static web (the largest REST system) works Use URLs that look like URLs for static web pages Utilize HTTP request methods and headers Stateless, i.e. no session

RESTful Web Service Example User Management List Get Add Update Delete

Create a RESTful Web Service Identify resources and operations Determine resource representation, i.e. data exchange format between the service and the clients Design URL and request mapping Implement the operations

Resource Representation XML Already widely in use as a platform independent data exchange format XML parsers are readily available in many languages JSON Much more concise than XML Can be used directly in JavaScript Data format should be easily “understandable” by all programming languages

URL Design and Request Mapping Conventions (1) Operation: get a user URL /user/{id} or /user/get?id={id} Path variable based design is usually preferred to request parameter based design.

URL Design and Request Mapping Conventions (2) Operation: get a user Choose which data format to use Solution: /user/{id}.{format} Check the Accept request header Checking Accept header is preferred in theory, but the URL based solution is more convenient in practice, e.g.

URL Design and Request Mapping Conventions (3) Map HTTP Request Methods to CRUD operations POST (or PUT ) GET PUT (or POST ) DELETE Create Retrieve Update Delete

Request Mapping Example GET /user/1 HTTP 1.1 Get a user Operation Delete a user DELETE /user/1 HTTP 1.1 HTTP Request Update a user PUT /user/1 HTTP 1.1 { “id”:1, “firstName”:“John”, “lastName”:“Doe”,

Service Implementation – Know Your Libraries Map HTTP requests to service operations Modern webapp framework like Spring Jersey - Convert between objects and XML/JSON Simple XML Serialization Jackson -

Serialization and Deserialization Java Object XML/JSON Serialization De-serialization

Service Implement Example: Simple XML Serialization Dependency org.simpleframework:simple-xml Usage Content type Serializer and Persister

Service Implementation Example: Jackson Dependency com.fasterxml.jackson.core:jacks on-databind Additional view resolver BeanNameViewerResolver Additional view MappingJackson2JsonView

Using Multiple View Resolvers in Spring View resolution order Order of the resolver beans, or Based on the order property of the beans InternalResourceViewResolver should always be the last

Access RESTful Web Service Apache HttpClient HttpUrlConnection HttpURLConnection.html HttpURLConnection.html Examples: XmlClient and JsonClient CSNS Android App -

Summary RPC and RMI CORBA IDL SOAP, WSDL, UDDI Create and consume SOAP web services using Metro RESTful web services

Further Readings Java Web Services Up and Running by Martin Kalin RESTful Java Web Services by Jose Sandoval The Rise and Fall of CORBAThe Rise and Fall of CORBA by Michi Henning