Download - Web Service and Mobile Integrated Day I
![Page 2: Web Service and Mobile Integrated Day I](https://reader033.vdocument.in/reader033/viewer/2022052619/55583e46d8b42ac6078b4d6a/html5/thumbnails/2.jpg)
About
● Not a Teacher or Instructor● Not a Programmer or Developer● Senior Software Engineer at SIPA● Content writer not speaker● I use Linux :)
![Page 3: Web Service and Mobile Integrated Day I](https://reader033.vdocument.in/reader033/viewer/2022052619/55583e46d8b42ac6078b4d6a/html5/thumbnails/3.jpg)
Rules
● You can leave every time.● If you don't understand and you don't want to
ask you can leave.● If you want to learn by yourself and I'll give
you a resources, you can leave.● If you don't understand at all and everything
as I said, you can leave and I'll give a resources, you can learning by yourself.
![Page 4: Web Service and Mobile Integrated Day I](https://reader033.vdocument.in/reader033/viewer/2022052619/55583e46d8b42ac6078b4d6a/html5/thumbnails/4.jpg)
Quote
“If you cannot do great things, do small things in a great way” - Napoleon Hill
![Page 5: Web Service and Mobile Integrated Day I](https://reader033.vdocument.in/reader033/viewer/2022052619/55583e46d8b42ac6078b4d6a/html5/thumbnails/5.jpg)
You should know
● Android● Java● PHP or some PHP Framework● Database System ● Service Oriented Architecture (SOA)● HTTP Services● XML, JSON, Data Parsing
![Page 6: Web Service and Mobile Integrated Day I](https://reader033.vdocument.in/reader033/viewer/2022052619/55583e46d8b42ac6078b4d6a/html5/thumbnails/6.jpg)
Web Service
A Web service is a method of communication between two electronic devices over the World Wide Web. A Web service is a software function provided at a network address over the web or the cloud, it is a service that is "always on" as in the concept of utility computing.
![Page 7: Web Service and Mobile Integrated Day I](https://reader033.vdocument.in/reader033/viewer/2022052619/55583e46d8b42ac6078b4d6a/html5/thumbnails/7.jpg)
Web Service
Two major classes of Web services● REST-compliant Web services● other
![Page 8: Web Service and Mobile Integrated Day I](https://reader033.vdocument.in/reader033/viewer/2022052619/55583e46d8b42ac6078b4d6a/html5/thumbnails/8.jpg)
Web Services in old fashion
It has an interface described in a machine-processable format (specifically Web Services Description Language, known by the acronym WSDL)
![Page 9: Web Service and Mobile Integrated Day I](https://reader033.vdocument.in/reader033/viewer/2022052619/55583e46d8b42ac6078b4d6a/html5/thumbnails/9.jpg)
Interact
Systems interact with the Web service in a manner prescribed by its description using SOAP messages, typically conveyed using HTTP with an XML serialization in conjunction with other Web-related standards.
![Page 10: Web Service and Mobile Integrated Day I](https://reader033.vdocument.in/reader033/viewer/2022052619/55583e46d8b42ac6078b4d6a/html5/thumbnails/10.jpg)
![Page 11: Web Service and Mobile Integrated Day I](https://reader033.vdocument.in/reader033/viewer/2022052619/55583e46d8b42ac6078b4d6a/html5/thumbnails/11.jpg)
Simple diagram
Requester Provider
Yellow Pages
Requester ask or search yellow pages which address and how to talk with provider. The yellow pages 'll send the response by using WSDL how to talk which provide by Provider to the requester.
Requester receives the address and methods then communicate with Provider.
WSDL
WSDL
WSDL
SOAP
![Page 13: Web Service and Mobile Integrated Day I](https://reader033.vdocument.in/reader033/viewer/2022052619/55583e46d8b42ac6078b4d6a/html5/thumbnails/13.jpg)
SOAP Sample
If you want to request to SOAP server, you must know● URL
○ http://example.com/service.php● WSDL
○ http://example.com/service.php?wsdl● Soap Action
○ http://example.com/service.php/HelloWorld● Method
○ HelloWorld● Your data to sent
![Page 14: Web Service and Mobile Integrated Day I](https://reader033.vdocument.in/reader033/viewer/2022052619/55583e46d8b42ac6078b4d6a/html5/thumbnails/14.jpg)
SOAP RequestPOST /InStock HTTP/1.1
Host: www.example.org
Content-Type: application/soap+xml; charset=utf-8
Content-Length: nnn
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
<soap:Body xmlns:m="http://www.example.org/stock">
<m:GetStockPrice>
<m:StockName>IBM</m:StockName>
</m:GetStockPrice>
</soap:Body>
</soap:Envelope>
![Page 15: Web Service and Mobile Integrated Day I](https://reader033.vdocument.in/reader033/viewer/2022052619/55583e46d8b42ac6078b4d6a/html5/thumbnails/15.jpg)
SOAP ResponseHTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: nnn
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
<soap:Body xmlns:m="http://www.example.org/stock">
<m:GetStockPriceResponse>
<m:Price>34.5</m:Price>
</m:GetStockPriceResponse>
</soap:Body>
</soap:Envelope>
![Page 16: Web Service and Mobile Integrated Day I](https://reader033.vdocument.in/reader033/viewer/2022052619/55583e46d8b42ac6078b4d6a/html5/thumbnails/16.jpg)
Web services in new fashion
Web API is a development in Web services where emphasis has been moving away from SOAP based services towards representational state transfer (REST) based communications.
![Page 17: Web Service and Mobile Integrated Day I](https://reader033.vdocument.in/reader033/viewer/2022052619/55583e46d8b42ac6078b4d6a/html5/thumbnails/17.jpg)
RESTFul / REST API
a style of software architecture for distributed systems such as the WWW. The REST language uses nouns and verbs, and has an emphasis on readability. Unlike SOAP, REST does not require XML parsing and does not require a message header to and from a service provider.
![Page 18: Web Service and Mobile Integrated Day I](https://reader033.vdocument.in/reader033/viewer/2022052619/55583e46d8b42ac6078b4d6a/html5/thumbnails/18.jpg)
Concept
● the base URI for the web service, such as http://example.com/resources/
● the Internet media type of the data supported by the web service.
● the set of operations supported by the web service using HTTP methods (e.g., GET, PUT, POST, or DELETE).
● The API must be hypertext driven.
![Page 19: Web Service and Mobile Integrated Day I](https://reader033.vdocument.in/reader033/viewer/2022052619/55583e46d8b42ac6078b4d6a/html5/thumbnails/19.jpg)
Example URI
● http://example.org/user/● http://example.org/user/anuchit● http://search.twitter.com/search.json?q=xxx
![Page 20: Web Service and Mobile Integrated Day I](https://reader033.vdocument.in/reader033/viewer/2022052619/55583e46d8b42ac6078b4d6a/html5/thumbnails/20.jpg)
Example methods
Resource GET PUT POST DELETE
http://example.org/user list collection replace create delete
http://example.org/user/rose list data replace/ create ? / create delete
![Page 21: Web Service and Mobile Integrated Day I](https://reader033.vdocument.in/reader033/viewer/2022052619/55583e46d8b42ac6078b4d6a/html5/thumbnails/21.jpg)
No "official" standard
There is no "official" standard for RESTful web services, This is because REST is an architectural style, unlike SOAP, which is a protocol. Even though REST is not a standard, a RESTful implementation such as the Web can use standards like HTTP, URI, XML, etc.
![Page 22: Web Service and Mobile Integrated Day I](https://reader033.vdocument.in/reader033/viewer/2022052619/55583e46d8b42ac6078b4d6a/html5/thumbnails/22.jpg)
Simple Diagram
Requester Provider
GET /user/anuchit HTTP/1.1
200 with some data
![Page 23: Web Service and Mobile Integrated Day I](https://reader033.vdocument.in/reader033/viewer/2022052619/55583e46d8b42ac6078b4d6a/html5/thumbnails/23.jpg)
Data Format
XML
<?xml version="1.0"?><item> <name>Anuchit Chalothorn</name> <email>[email protected]</email></item><item> <name>Sira Nokyongthong</name> <email>[email protected]</email></item>
![Page 24: Web Service and Mobile Integrated Day I](https://reader033.vdocument.in/reader033/viewer/2022052619/55583e46d8b42ac6078b4d6a/html5/thumbnails/24.jpg)
Data Format
JSON{ "item": [ { "name": "Anuchit Chalothorn", "email": "[email protected]" }, { "name": "Sira Nokyongthong", "email": "[email protected]" } ]}
![Page 25: Web Service and Mobile Integrated Day I](https://reader033.vdocument.in/reader033/viewer/2022052619/55583e46d8b42ac6078b4d6a/html5/thumbnails/25.jpg)
Shortcut - Web Services design
● Choose method old style, new style● Look around an eco-system● Who'll using your services● How to implementation● Design and document
![Page 26: Web Service and Mobile Integrated Day I](https://reader033.vdocument.in/reader033/viewer/2022052619/55583e46d8b42ac6078b4d6a/html5/thumbnails/26.jpg)
Mobile App & Web Services
Provider
Data Req
(2)Data
(1)Parse Res Data
http request
response
* This is your destiny you cannot change your future, accept using vendor sdk's
![Page 27: Web Service and Mobile Integrated Day I](https://reader033.vdocument.in/reader033/viewer/2022052619/55583e46d8b42ac6078b4d6a/html5/thumbnails/27.jpg)
Case Study - Plus Clever
● Game (Client)○ sum a set of numbers in to 1 digit ○ score by level calculate from time remain and levels○ each level has 10 sub-levels○ never ending game BUT maximum is 10 digits to
calculate○ keep your high-score online (web service is here)
● Web Service (Server)○ PaaS on OpenShift○ PHP, CakePHP, MySQL
![Page 28: Web Service and Mobile Integrated Day I](https://reader033.vdocument.in/reader033/viewer/2022052619/55583e46d8b42ac6078b4d6a/html5/thumbnails/28.jpg)
Case Study - Plus Clever
Dakota
Enter Your Name
Ask a player name in the first time and keep value in SQLite
![Page 29: Web Service and Mobile Integrated Day I](https://reader033.vdocument.in/reader033/viewer/2022052619/55583e46d8b42ac6078b4d6a/html5/thumbnails/29.jpg)
Case Study - Plus Clever
If player reach high score keep score in SQLite and publish score to server
Your Score
1,000,000
![Page 30: Web Service and Mobile Integrated Day I](https://reader033.vdocument.in/reader033/viewer/2022052619/55583e46d8b42ac6078b4d6a/html5/thumbnails/30.jpg)
Case Study - Plus Clever
World LeaderboardXavier - 10,000,000Dakota - 1,000,000
Luxor - 50,000Keva - 6,000
Ask score server for world leader board.
![Page 31: Web Service and Mobile Integrated Day I](https://reader033.vdocument.in/reader033/viewer/2022052619/55583e46d8b42ac6078b4d6a/html5/thumbnails/31.jpg)
Case Study - Plus Clever
● REST API ● Using JSON as data● Using CakePHP to implement score service● Put in the Cloud ~ OpenShift by RedHat
![Page 32: Web Service and Mobile Integrated Day I](https://reader033.vdocument.in/reader033/viewer/2022052619/55583e46d8b42ac6078b4d6a/html5/thumbnails/32.jpg)
In Real Life
● Plus Clever in Google Play○ http://tinyurl.com/plusclever
● Score server○ https://rest-redlinemobi.rhcloud.com/score/
![Page 33: Web Service and Mobile Integrated Day I](https://reader033.vdocument.in/reader033/viewer/2022052619/55583e46d8b42ac6078b4d6a/html5/thumbnails/33.jpg)
Code in GitHub
● Score Server ○ https://github.com/anoochit/rest-score
● Score Server Test○ https://github.com/anoochit/rest-score-test
● Plus Clever Game○ https://github.com/anoochit/plusclaver-game
![Page 34: Web Service and Mobile Integrated Day I](https://reader033.vdocument.in/reader033/viewer/2022052619/55583e46d8b42ac6078b4d6a/html5/thumbnails/34.jpg)
Your Case Study - WattPad ?
I'm too old, anyone can describe this● What is WattPad ?● What is WattPad do ?● Who are using WattPad ?● How to use WattPad ? ... ... ...
![Page 35: Web Service and Mobile Integrated Day I](https://reader033.vdocument.in/reader033/viewer/2022052619/55583e46d8b42ac6078b4d6a/html5/thumbnails/35.jpg)
Quote
“If you cannot do great things, do small things in a great way” - Napoleon Hill
![Page 36: Web Service and Mobile Integrated Day I](https://reader033.vdocument.in/reader033/viewer/2022052619/55583e46d8b42ac6078b4d6a/html5/thumbnails/36.jpg)
Small things for you
Make Web Services of this small things● HelloWorld● Echo your name● Asking for Date Time● Temperature Unit Converter● Search Telephone Number
![Page 37: Web Service and Mobile Integrated Day I](https://reader033.vdocument.in/reader033/viewer/2022052619/55583e46d8b42ac6078b4d6a/html5/thumbnails/37.jpg)
Small things for you
Make Mobile App by calling your web service● HelloWorld● Echo your name● Asking for Date Time● Temperature Unit Converter● Search Telephone Number
![Page 38: Web Service and Mobile Integrated Day I](https://reader033.vdocument.in/reader033/viewer/2022052619/55583e46d8b42ac6078b4d6a/html5/thumbnails/38.jpg)
PHP (native)
You can use json_encode() function to generate JSON string from mix value like associative array
$data = array("result"=>"hello","success"=>true);echo json_encode($data);
![Page 39: Web Service and Mobile Integrated Day I](https://reader033.vdocument.in/reader033/viewer/2022052619/55583e46d8b42ac6078b4d6a/html5/thumbnails/39.jpg)
Browser use GET method
if you want to test your RESTful web service by sent another method, try this ● Advanced REST Client for Chrome● REST Client for Firefox
![Page 40: Web Service and Mobile Integrated Day I](https://reader033.vdocument.in/reader033/viewer/2022052619/55583e46d8b42ac6078b4d6a/html5/thumbnails/40.jpg)
Call Web Service
Android RESTServer
200 OK with XML or JSON string
GET /user/anoochit
● Check request method● Parse data from URI● Process● Return XML or JSON string
● HTTP request● Method GET, POST, PUT or DELETE● Get BufferReader and pack into
"String" <= JSON String● Parse "String Key"● Get your value
![Page 41: Web Service and Mobile Integrated Day I](https://reader033.vdocument.in/reader033/viewer/2022052619/55583e46d8b42ac6078b4d6a/html5/thumbnails/41.jpg)
Small resources
● Thai Create Good Mobile Tutorial○ http://www.thaicreate.com/mobile.html
![Page 42: Web Service and Mobile Integrated Day I](https://reader033.vdocument.in/reader033/viewer/2022052619/55583e46d8b42ac6078b4d6a/html5/thumbnails/42.jpg)
2 Hoursfinish & present
![Page 43: Web Service and Mobile Integrated Day I](https://reader033.vdocument.in/reader033/viewer/2022052619/55583e46d8b42ac6078b4d6a/html5/thumbnails/43.jpg)
Your Code
Check out an example for REST Server and Mobile Client at ● https://github.com/anoochit/spurest
![Page 44: Web Service and Mobile Integrated Day I](https://reader033.vdocument.in/reader033/viewer/2022052619/55583e46d8b42ac6078b4d6a/html5/thumbnails/44.jpg)
Thank You