INFO 344 Web Tools And Development CK Wang University of Washington Spring 2014
Intro to Web Services
Web site vs. Web service Web site Web service User Software/Code http gethtml Browser A lot of similarities, in fact, html is kinda like xml You could say that web sites are a subset of web services But easier explanation => for people vs. for code. For person to consume For software to consume rest/soapxml/json
How do Web Services communicate?
Communication Data Format Service Protocol Application Layer Protocol Network Transport Protocol JSON, XML REST/SOAP/WSDL HTTP, SMTP, FTP, SSH TCP, UDP And more! But we’ll focus on these ones Data link layer
Data Format XML (1996) – Extensible Markup Language – Language independent – More verbose than JSON – Open/Close tags
Data Format JSON (2001) – Javascript Object Notion – Originally from JS (how to create JS objects/properties) – Now => language independent – Usually less bytes than XML – – XML was probably too much of a hassle to parse in JS (and type-less) Try this!
Data Format Takeaway – Both formats are language independent – Usually have native parsers/serializers for both – Size difference may be ~30% but after zipping may be negligible – So feel free to pick your favorite but generally: Web/JS/REST/type-less = JSON SOAP/non-web/Microsoft stack/strong type = XML Will show you later…
Service Protocol REST – Representational State Transfer – Invented along with HTTP – Goals: performance, scalability, simplicity – Uses HTTP request methods GET/POST/PUT/DELETE => simple! – Constraints: Client-server = separate responsibility, server not concerned with UI (scalable), client not concerned with state. Stateless = client doesn’t store data (portable) Others (see Wikipedia)
Service Protocol SOAP – Simple Object Access Protocol – Designed by Microsoft (1998) – Goals: Exchanging structured information, successor of XML-RPC – RPC = remote procedural call (you’ll see that it looks more like calling a function) – Not client-server (you can call a function in my machine and I can call a function in yours) – distributed – Not stateless (client stores the data to use it!) – Originally not over HTTP but now HTTP is so much more popular, it’s commonly used over HTTP.
Recap Active Server Method File (ASMX) – Microsoft’s implementation of web services – It’s actually a very neat/clean implementation! – Recap Add [WebMethod] to specify that it’s a web service method Add parameters into function Return value can be objects!!
Recap Make a web service with the following & upload to your Azure account Remember!!! Before closing Try this!
REST Call your web service on Azure via REST! /WebService.asmx/OddNumbers?n=23 – Just like HTTP/web! Pass parameter and this does a http get. – Performance = fast! – Simplicity = just pass param “n=23” – Scalable/Portable = do this on any machine! Try this!
SOAP Call your web service on Azure via SOAP! – This is magic. – Create new project (Windows, Console proj, C#) – Right click service (add service reference) /WebService.asmx – Now you can call all those functions! RPC! Wait… there’s an error… Search on Google!! Try this!
SOAP Magic! How did the client code get generated? WSDL = asmx?WSDL asmx?WSDL Remember: – Goals: Exchanging structured information, successor of XML-RPC – RPC = remote procedural call (you’ll see that it looks more like calling a function)
REST vs SOAP Long religious fight online My opinion: – Web/JS/REST/type-less = JSON More scalable, if you’re writing an API for anyone in the world to use (probably better to do REST/JSON) – SOAP/non-web/Microsoft stack/strong type = XML More convenient, if you’re writing an API for only Microsoft to use that interacts with a lot of client software => SOAP/XML = great! Others = JSON-RPC/etc => too much work, not natural. Fortunately, ASMX does both! Automatically!!
Application Layer Examples = HTTP, SMTP, FTP, SSH Status codes: rfc2616/rfc2616-sec10.html
HTTP GET vs. POST Also easier to test
Network Transport Protocol TCP – Transmission Control Protocol – Reliable transmission = resend lost packets – Either receiver asks for retransmission or sender auto re- sends if not received ack packet – Sliding window protocol = cause throughput to drop – FTP/SMTP/SSH/HTTP = all TCP!
Network Transport Protocol UDP – User Datagram Protocol – Unreliable transmission = dropped packets are ignored – Time-sensitive applications – Voice (VoIP), Video (Netflix streaming) => all UDP. – MMO Games (player position) = UDP – But In-app purchase/transactions = TCP! – Use UDP when lost packets = no longer needed.
Apple Game Center Real world example! entation/NetworkingInternet/Conceptual/Game Kit_Guide/Matchmaking/Matchmaking.html Section: Exchanging Data Between Match Participants
Group Discussion! Groups of 3 Think of an example for TCP Think of an example for UDP (excluding the ones I gave)
Recap: Communication Data Format Service Protocol Application Layer Protocol Network Transport Protocol JSON, XML How data is formatted REST/SOAP/WSDL How data is communicated HTTP, SMTP, FTP, SSH How applications communicate TCP, UDP How packets are communicated
Recap: Key topics XML vs. JSON REST vs. SOAP ASMX does both! HTTP message TCP vs. UDP
PA2 hints index.html – Text input – AJAX calls your web service – Updates query suggestion/hints getQuerySuggestions.asmx – Return JSON suggestions (only need 10) – Case insensitive
PA2 hints Preprocess your data!!! – Remove pages with non-english char – Remove pages with digits Goal = Great User Experience
Questions?