Webservices

2,112 views
2,021 views

Published on

Seminar presentation on Webservices by venkateswara rao at Nyros Technologies, kakinada, India.

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

No Downloads
Views
Total views
2,112
On SlideShare
0
From Embeds
0
Number of Embeds
87
Actions
Shares
0
Downloads
165
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Webservices

  1. 1. Web Services The Next Generation Web Technology
  2. 2. Contents <ul><li>Overview </li></ul><ul><li>What are web services </li></ul><ul><li>What are the uses of web services </li></ul><ul><li>How they implement </li></ul><ul><li>Basics of SOAP and XML </li></ul><ul><li>Why use PHP </li></ul><ul><li>One sample application </li></ul>
  3. 3. Overview <ul><li>In a Normal web surfing scenario, a visitor visits a website and use the functionality provided by that particular website. User sends HTTP request to server from web browsers and server taken user’s request, processed and send response back to the user through browser. This is the process of website surfing by end user. Ex: www.inkakinada.com will provide lot of services to the end users like movies, news, jobs etc., information. </li></ul>
  4. 4. Overview <ul><li>Here, we cant get the www.inkakinada.com services by visiting www.nyros.com . Am I right? But it is also possible with web services, the name it self gives the meaning. Services provided by web. What exactly means You don’t need to visit the particular website to use their service and functionality if they are providing web services </li></ul><ul><li>So Web services are used to share the resource among the websites. </li></ul>
  5. 5. What are web services? <ul><li>Web services are the set of platform independent exposed functions which can be used to share logic (or data) across many websites, platforms and hardware configurations. </li></ul><ul><li>Hence web services are platform independent and language independent. Means JAVA web services can be used PHP Developers and vice versa. </li></ul><ul><li>There are two parties involved in web services, one is web service provider and other called web service consumer. </li></ul>
  6. 6. Uses of web services? <ul><li>Exposing your existing functionality through out the web with no cost </li></ul><ul><li>Retrieve information dynamically over the web </li></ul><ul><li>Connecting Different Applications i.e Interoperability </li></ul><ul><li>No Cost for communication </li></ul>
  7. 7. How they implement? <ul><li>There are different methods available for developing web services but below three are the most common methods </li></ul><ul><li>SOAP </li></ul><ul><li>XML–RPC </li></ul><ul><li>REST </li></ul><ul><li>SOAP is the best choice for PHP Developers to develop Web services </li></ul>
  8. 8. SOAP <ul><li>SOAP is the acronym of Simple Object Access Protocol. It is a transport protocol for the client request to the web service and response to the client from web service. </li></ul><ul><li>Web services uses the language XML to encode and decode your data and used the transport protocol SOAP to transport xml data between client and server. </li></ul><ul><li>Nusoap is the toolkit of PHP for providing and consuming web services using SOAP in PHP . </li></ul>
  9. 9. XML <ul><li>Web services send and receive data in the form of Extensible Markup Language (XML), which travel via Simple Object Access Protocol (SOAP). </li></ul><ul><li>XML [Extensible markup language] is a language which can be used for share information between different applications irrespective of platforms [windows / Linux etc] and languages [JAVA / PHP / .NET / ROR etc]. Hence XML is platform independent and language independent. </li></ul>
  10. 10. Why use PHP <ul><li>Already a very popular for web development </li></ul><ul><li>XML support </li></ul><ul><li>CURL support </li></ul><ul><li>OOP </li></ul><ul><li>SOAP extension etc., </li></ul><ul><li>Lot of important tools available freely </li></ul>
  11. 11. Sample Application <ul><li>Here we implement one sample application which provides STD code for the city. </li></ul><ul><li>Assume one website which contains all the cities zip codes. </li></ul><ul><li>So he would like to provide this resources through out the web to the people who wants to find zip codes for the cities. </li></ul><ul><li>First he create one web service in his website. </li></ul>
  12. 12. Code for creating service <ul><li>include(&quot;nusoap.php&quot;); </li></ul><ul><li>include(&quot;dbconfig.php&quot;); </li></ul><ul><li>$server = new soap_server(); </li></ul><ul><li>$server->register(&quot;getSTD&quot;); </li></ul><ul><li>function getSTD($city) </li></ul><ul><li>{ </li></ul><ul><li>$query=&quot;select * from cities where cityname=$city&quot;; </li></ul><ul><li>$res=mysql_query($query); </li></ul><ul><li>$rs=mysql_fetch_assoc($res); </li></ul><ul><li>$output=$rs['std_code']; </li></ul><ul><li>return array(&quot;data&quot;=>&quot;$output &quot;); </li></ul><ul><li>} </li></ul><ul><li>Here $ output will have the STD code for the city passed as </li></ul><ul><li>parameter...... </li></ul>
  13. 13. Code for Calling Service <ul><li>include(&quot;nusoap.php&quot;); </li></ul><ul><li>$soap = new soapclient_nusoap(&quot;http://example.com/webservice.php&quot;); </li></ul><ul><li>$args = array('city'=>'kakinada'); </li></ul><ul><li>$output = $soap->call(&quot;getSTD&quot;,$args); </li></ul><ul><li>print_r($output);//it gives output as array </li></ul>
  14. 14. What is missing? <ul><li>What happened </li></ul><ul><li>If you don't pass a City name? </li></ul><ul><li>If you don’t pass currect city name </li></ul><ul><li>If the database doesn’t contain result with the city name you passed even it is correct </li></ul><ul><li>SOAP Fault generation is the solution </li></ul>
  15. 15. SOAP FAULT <ul><li>Just change you service code </li></ul><ul><li>include(&quot;nusoap.php&quot;); </li></ul><ul><li>include(&quot;dbconfig.php&quot;); </li></ul><ul><li>$server = new soap_server(); </li></ul><ul><li>$server->register(&quot;getSTD&quot;); </li></ul><ul><li>function getSTD($city) </li></ul><ul><li>{ </li></ul><ul><li>$query=&quot;select * from cities where cityname=$city&quot;; </li></ul><ul><li>$res=mysql_query($query); </li></ul><ul><li>$rs=mysql_fetch_assoc($res); </li></ul><ul><li>$output=$rs['std_code']; </li></ul><ul><li>If($city==‘’ OR $output==‘’){return new soap_fault(‘Must supply valid city name’) } </li></ul><ul><li>else { return array(&quot;data&quot;=>&quot;$output &quot;); } </li></ul><ul><li>} </li></ul>
  16. 16. SOAP Work Here <ul><li>Soap transfer the request and response very securely. </li></ul><ul><li>Soap packed the message securely and called it as soap envelop which contains 3 parts as below </li></ul><ul><li>1. Soap header, 2. Soap body, 3. Soap fault </li></ul><ul><li>Soap header will contain any additional information to be send along with method call, like authentication information, security info etc, soap body will contain actual web service method call information with necessary parameters or result of method execution soap fault will contain error info </li></ul>
  17. 17. Alternate Methods <ul><li>XML-RPC [Remote Procedure Call] </li></ul><ul><li>Another way of providing and consuming web services. It uses XML to encode and decode the remote procedure call along with it’s parameter. You can visit the official website www.xmlrpc.com to know more about XML-RPC. </li></ul><ul><li>REST </li></ul><ul><li>Representational State Trasfer(REST) is comparatively simpler method for providing and consuming web services. It is not necessary to use XML as a data interchange format in REST. To know more about REST visit http://www.crummy.com/writing/RESTful-Web-Services/ </li></ul>
  18. 18. Soap References <ul><li>SOAP and web services reference sites: </li></ul><ul><li>http://www.xml.com/pub/a/2001/04/04/webservices/ </li></ul><ul><li>http://www.w3c.org/tr/soap </li></ul><ul><li>http://www.w3schools.com/SOAP/soap_intro.asp </li></ul>
  19. 19. XML References <ul><li>http://www.w3schools.com/xml/default.asp </li></ul><ul><li>http://www.w3.org/XML/ </li></ul><ul><li>http://www.xml.com/ </li></ul><ul><li>http://www.xml.org/ </li></ul>
  20. 20. GOOD LUCK

×