Web Service and Mobile Integrated Day I

2,790 views

Published on

Web Service and Mobile Integrated Day I 5 jan 2013 @ Sripatum University

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,790
On SlideShare
0
From Embeds
0
Number of Embeds
811
Actions
Shares
0
Downloads
39
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Web Service and Mobile Integrated Day I

  1. 1. Web Service for Mobile 5 jan 2013 @ Sripatum University Anuchit Chalothorn anoochit@gmail.com
  2. 2. About● Not a Teacher or Instructor● Not a Programmer or Developer● Senior Software Engineer at SIPA● Content writer not speaker● I use Linux :)
  3. 3. Rules● You can leave every time.● If you dont understand and you dont want to ask you can leave.● If you want to learn by yourself and Ill give you a resources, you can leave.● If you dont understand at all and everything as I said, you can leave and Ill give a resources, you can learning by yourself.
  4. 4. Quote“If you cannot do great things, do small thingsin a great way” - Napoleon Hill
  5. 5. You should know● Android● Java● PHP or some PHP Framework● Database System● Service Oriented Architecture (SOA)● HTTP Services● XML, JSON, Data Parsing
  6. 6. Web ServiceA Web service is a method of communicationbetween two electronic devices over the WorldWide Web. A Web service is a softwarefunction provided at a network address over theweb or the cloud, it is a service that is "alwayson" as in the concept of utility computing.
  7. 7. Web ServiceTwo major classes of Web services● REST-compliant Web services● other
  8. 8. Web Services in old fashionIt has an interface described in a machine-processable format (specifically Web ServicesDescription Language, known by the acronymWSDL)
  9. 9. InteractSystems interact with the Web service in amanner prescribed by its description usingSOAP messages, typically conveyed usingHTTP with an XML serialization in conjunctionwith other Web-related standards.
  10. 10. Simple diagram Yellow Pages WSDL WSDL WSDL Requester Provider SOAPRequester 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.
  11. 11. Quote"HTTP + XML = SOAP" - W3CSchool
  12. 12. SOAP SampleIf you want to request to SOAP server, youmust 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
  13. 13. SOAP RequestPOST /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>
  14. 14. 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>
  15. 15. Web services in new fashionWeb API is a development in Web serviceswhere emphasis has been moving away fromSOAP based services towardsrepresentational state transfer (REST) basedcommunications.
  16. 16. RESTFul / REST APIa style of software architecture for distributedsystems such as the WWW. The RESTlanguage uses nouns and verbs, and has anemphasis on readability. Unlike SOAP, RESTdoes not require XML parsing and does notrequire a message header to and from aservice provider.
  17. 17. 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.
  18. 18. Example URI● http://example.org/user/● http://example.org/user/anuchit● http://search.twitter.com/search.json?q=xxx
  19. 19. Example methodsResource GET PUT POST DELETEhttp://example.org/user list collection replace create deletehttp://example.org/user/rose list data replace/ create ? / create delete
  20. 20. No "official" standardThere is no "official" standard for RESTful webservices, This is because REST is anarchitectural style, unlike SOAP, which is aprotocol. Even though REST is not a standard,a RESTful implementation such as the Webcan use standards like HTTP, URI, XML, etc.
  21. 21. Simple Diagram GET /user/anuchit HTTP/1.1 Requester Provider 200 with some data
  22. 22. Data FormatXML<?xml version="1.0"?><item> <name>Anuchit Chalothorn</name> <email>anoochit@gmail.com</email></item><item> <name>Sira Nokyongthong</name> <email>gumaraa@gmail.com</email></item>
  23. 23. Data FormatJSON{ "item": [ { "name": "Anuchit Chalothorn", "email": "anoochit@gmail.com" }, { "name": "Sira Nokyongthong", "email": "gumaraa@gmail.com" } ]}
  24. 24. Shortcut - Web Services design● Choose method old style, new style● Look around an eco-system● Wholl using your services● How to implementation● Design and document
  25. 25. Mobile App & Web Services http request Data Req Provider (2) (1) Data Parse Res Data response * This is your destiny you cannot change your future, accept using vendor sdks
  26. 26. 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
  27. 27. Case Study - Plus Clever Enter Your Name Dakota Ask a player name in the first time and keep value in SQLite
  28. 28. Case Study - Plus Clever Your Score 1,000,000 If player reach high score keep score in SQLite and publish score to server
  29. 29. Case Study - Plus Clever World Leaderboard Xavier - 10,000,000 Dakota - 1,000,000 Luxor - 50,000 Keva - 6,000 Ask score server for world leader board.
  30. 30. Case Study - Plus Clever● REST API● Using JSON as data● Using CakePHP to implement score service● Put in the Cloud ~ OpenShift by RedHat
  31. 31. In Real Life● Plus Clever in Google Play ○ http://tinyurl.com/plusclever● Score server ○ https://rest-redlinemobi.rhcloud.com/score/
  32. 32. 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
  33. 33. Your Case Study - WattPad ?Im too old, anyone can describe this● What is WattPad ?● What is WattPad do ?● Who are using WattPad ?● How to use WattPad ? ... ... ...
  34. 34. Quote“If you cannot do great things, do small thingsin a great way” - Napoleon Hill
  35. 35. Small things for youMake Web Services of this small things● HelloWorld● Echo your name● Asking for Date Time● Temperature Unit Converter● Search Telephone Number
  36. 36. Small things for youMake Mobile App by calling your web service● HelloWorld● Echo your name● Asking for Date Time● Temperature Unit Converter● Search Telephone Number
  37. 37. PHP (native)You can use json_encode() function togenerate JSON string from mix value likeassociative array$data = array("result"=>"hello","success"=>true);echo json_encode($data);
  38. 38. Browser use GET methodif you want to test your RESTful web service bysent another method, try this● Advanced REST Client for Chrome● REST Client for Firefox
  39. 39. Call Web Service GET /user/anoochit REST Android Server 200 OK with XML or JSON string● HTTP request ● Check request method● Method GET, POST, PUT or DELETE ● Parse data from URI● Get BufferReader and pack into ● Process "String" <= JSON String ● Return XML or JSON string● Parse "String Key"● Get your value
  40. 40. Small resources● Thai Create Good Mobile Tutorial ○ http://www.thaicreate.com/mobile.html
  41. 41. 2 Hoursfinish & present
  42. 42. Your CodeCheck out an example for REST Server andMobile Client at● https://github.com/anoochit/spurest
  43. 43. Thank You

×