Building Web Services

Download Building Web Services

Post on 19-May-2015

354 views

Category:

Technology

1 download

Embed Size (px)

TRANSCRIPT

<ul><li> 1. BuildingWebServices JussiPohjolainen </li></ul> <p> 2. Communica9onbetweenApps Implemen9ngRPCscanbeadiculttask DCOM,CORBA,RMIrewallsandproxy serverscanblockbinary UsingHTTPforRPCsyoucanbypassthis problem 3. WebService Communica9onbetweendevicesoverWeb W3Cdenes"WebService"asatechnologythat usesWSDL,SOAP,HTTPandXMLtocreatethe communica9on Twotypes XMLWebServices WebAPI 4. XMLWebServices XMLWebservicesusesXMLmessagesthat followSOAPstandardforcrea9ngthe communica9on ServicesarewriRenusingWSDL WebServicesDescrip9onLanguage(WSDL) WebServicesareintegratedverywellto.NET andJava(6-&gt;) 5. WebAPI(Rest) Emphasistosimplercommunica9on Representa)onalstatetransfer(REST) DonotrequireSOAP,WSDL SimpleWebAPI hRp://www.something.com/twiRerthis.php? msg=hello! IftheWebAPIisimplementedusingcertain constraints,it'srestAPI hRp://www.something.com/clients/client17 6. XMLWEBSERVICE 7. SOAP? SOAPisaXML-basedprotocoltoletapps exchangeinforma9onoverHTTP SOAPislanguageindependentandit'sW3C recommenda9on SinceSOAPisXMLandit'stext,itcanbesend easilythroughrewalls 8. SOAPBuildingBlocks ... ... ... 9. SOAPRequest 5.6 10. SOAPResponse 98.5203456165759 11. ClientandServer "SoapServer"providesaWSDLletoclient ClientopenstheWSDLleanddiscoversthe methodsandargumentsofgivenservice Clientmakesainvoca9ontoserver.The invoka9onisasoapmessage Serverreceivesthesoapmessage,parsesit andinvocatesthemethod.Resultissendback inSOAPenvelope 12. Java6:XML&amp;WebServices Easywayofcrea9ngWebServices Exposewebservicewithasimpleannota9on 13. WebService package hello; import javax.jws.WebService; @WebService public class CircleFunctions { public double getArea(double r) { return java.lang.Math.PI * (r * r); } public double getCircumference(double r) { return 2 * java.lang.Math.PI * r; } } 14. Server package hello; import javax.xml.ws.Endpoint; class Publish { public static void main(String[] args) { Endpoint.publish( "http://localhost:8080/circlefunctions", new CircleFunctions()); } } 15. GenerateStubFiles Generatestubles: wsgen classpath . hello.CircleFunctions 16. PHPClient 17. REST 18. RESTConstraints ClientServer Interfaceseparatesclientsfromservers.Serverandclientcanbe replacedanddevelopedindependently Client?Browser,PHPscript,Desktopapp,Commandline Statelessness Eachrequestfromanyclientcontainsalltheinforma9onnecessary Cacheable Clientscancacheresponses.Responseindicatewhetheritiscacheable ornot Uniforminterface Uniforminterfacebetweenclientsandservers.Fourguidingprinciples LayeredSystem Clientdoesnotknowisitconnecteddirectlytoserverorsome middleware 19. GuidelinesfortheInterface Iden9ca9onofresources Resourcesareiden9edviarequestusingURIs ServersendstoclientHTML,XMLorJSONasresult(doesnotsendthe database) Manipula9onofresources Clientcandeleteormodifyaresourcewhenitholdsarepresenta9on oftheresource Self-descrip9vemessages Messageincludesenoughinforma9ontodescribehowtoprocessthe message Hypermediaastheengineofapplica9onstate CliententersRESTappusingsimplexedURL.Allfutureac9onsthe clientmaytakecanbediscoveredfromthereturnedrepresenta9on 20. Resources Resourcecanbeanything:ar9cle,comment, user ResourcesareaccessedbyURI hRp://example.com/ar9cle/1 hRp://example.com/comments/ 21. RESTfulWebAPIs 22. PHPRESTIMPLEMENTATION 23. Rewriteengine Rewriteengineisasohwarethatmodies webURL'sappearance URLrewri9ng Usage hRp://example.com/index.php?clien9d=123 Canbealtered hRp://example.com/clients/client/123 ApacheHTTPServerhasURLrewri9ng providedbymod_rewritemodule 24. .htaccess # Let's use the mod_rewrite module RewriteEngine On # Set's the base URL for per-directory rewrites RewriteBase / # Defines a condition under which rewriting will # take place RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # Make the rule RewriteRule ^(.*)$ /xampp/rest/index.php/$1 [L] 25. XAMPPwindows Openapache/conf/extra/hRpd-xampp.conf setAllowOverrideAll 26. GeknginfoaboutRequestandPath 27. Modica9on 28. Encodinganddecoding EncodedatatoanddecodefromJSON json_encode() json_decode() 29. Tes9ng:AdvancedRESTClientChromeApp 30. Tes9ng PHPScriptthatmakeshRprequests CURL Telnet </p>

Recommended

View more >