• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
PHP Web Services PHP Web Services PHP Web Services PHP Web ...
 

PHP Web Services PHP Web Services PHP Web Services PHP Web ...

on

  • 6,525 views

 

Statistics

Views

Total Views
6,525
Views on SlideShare
6,525
Embed Views
0

Actions

Likes
1
Downloads
117
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    PHP Web Services PHP Web Services PHP Web Services PHP Web ... PHP Web Services PHP Web Services PHP Web Services PHP Web ... Document Transcript

    • Some Quotes „Many Web Services Initiatives Risk Failure” » Gartner, July 2003 PHP Web Services „Gartner Says Web Services Ready for Prime Time“ » eWeek, May 2004 „Gartner predicts American Christian Wenz business is going to squander $1 billion on misguided Web services chw@hauser-wenz.de projects by 2007 “ » CIO Magazine, October 2003 27 June 2006 NYPHPCon 2006 Slide 1 27 June 2006 NYPHPCon 2006 Slide 2 And What About PHP? Aim Of This Presentation • Focus on .NET and J2EE What‘s this Web Services stuff all about? • In comparisons, PHP gets very What‘s about these acronyms? little attention How can I consume (use) Web • However Googlefight knows: Services with PHP? There must be a way: ☺ How can I create my own Web Services with PHP? PHP 4 vs. PHP 5 27 June 2006 NYPHPCon 2006 Slide 3 27 June 2006 NYPHPCon 2006 Slide 4 Agenda Web Services – The Idea A: Web Services – The Idea Web Services are used for business-to-business B: Web Services – The Standards communication C: Web Services in PHP This idea is rather old, however (D: Wish List) now there are specifications that describe how information is exchanged 27 June 2006 NYPHPCon 2006 Slide 5 27 June 2006 NYPHPCon 2006 Slide 6
    • Web Services – Data Transmission Old Idea, New Idea, Both? Often, data is transmitted using HTTP No, Web Services are no new » Good: Goes through most firewalls concept » Bad: Firewall makers upgrade their systems No, Web Services were not invented (nor patented) by Microsoft However: Microsoft worked on many of the standards (!) However: Microsoft (and many others) promote Web Services with their huge budgets 27 June 2006 NYPHPCon 2006 Slide 7 27 June 2006 NYPHPCon 2006 Slide 8 Key Players Why Is Everybody Using This? Dave Winer – worked on XML-RPC Standards enable communication Don Box – Microsoft‘s Web Services guru (but started between totally different machines on the standardization with his own company) (and developers) IBM, HP, ... Use of XML which is sexy, cool (and: human-readable, Reference implementations (Amazon, Google, standardized) Yahoo!, Dell) Machine-to-Machine Standardization committees (W3C, OASIS) communication means: No human interaction involved Gartner says it‘s important! ☺ 27 June 2006 NYPHPCon 2006 Slide 9 27 June 2006 NYPHPCon 2006 Slide 10 Why Should You Be Using This? Why Not? Currently, rather few visible implementations (Amazon, Google, Yahoo!, eBay et al.) It may be a hype However, Web Services offer many possibilities: Remember WAP? » Communication between servers (or websites) is easy It is rather useless to use a Web » Platform independence Service on one page and call it from » New Markets, new business models another page on the same web server » More and more support in the various languages and technologies KISS vs. early adopting Currently, 18 PEAR packages 27 June 2006 NYPHPCon 2006 Slide 11 27 June 2006 NYPHPCon 2006 Slide 12
    • Agenda What About These Acronyms? A: Web Services – The Idea Enough inspiration for a whole round of buzzword bingo B: Web Services – The Standards » XML-RPC C: Web Services in PHP » SOAP (D: Wish List) » WSDL » UDDI » DISCO » REST However, PHP takes care of most of this stuff for you 27 June 2006 NYPHPCon 2006 Slide 13 27 June 2006 NYPHPCon 2006 Slide 14 XML-RPC Let‘s Have A Look A request POST /webservice.php HTTP/1.1 „XML Remote Procedure Call(s)“ Host: www.hauser-wenz.de Used for message exchange using Content-Type: text/xml; charset=utf-8 HTTP and XML Content-Length: 1234 Quite easy to use <?xml version="1.0" encoding="utf-8"?> <methodCall> Developed by Dave Winer (so we <methodName>hauserwenz.GetStockPrice</methodName> thought) <params> However, done in then-secret <param><value><string>PHP</string></value></param> </params> cooperation with Microsoft </methodCall> 27 June 2006 NYPHPCon 2006 Slide 15 27 June 2006 NYPHPCon 2006 Slide 16 Let‘s Have A Look (2) So, What Do You Think? A response HTTP/1.1 200 OK Good: Content-Type: text/xml; charset="utf-8" » Easy to use Content-Length: 1234 » Not too much code overhead <?xml version="1.0" encoding="utf-8"?> » Quite in use, e.g. PEAR project <methodResponse> » Short learning curve (you could do this <params> manually) <param><value><string>$41.00</string></value></param> </params> Bad: </methodResponse> » Not „standardized“ by a committee » Quite complex with simple data » No user-defined data types 27 June 2006 NYPHPCon 2006 Slide 17 27 June 2006 NYPHPCon 2006 Slide 18
    • SOAP Let‘s Have A Look Successor of XML-RPC A request POST /webservice.php HTTP/1.1 Used to be an acronym for „Simple Object Access Host: www.hauser-wenz.de Content-Type: text/xml; charset=utf-8 Protocol“ Content-Length: 1234 SOAPAction: "http://hauser-wenz.de/GetStockPrice" Is, however, neither simple nor relevant for object access <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema- Therefore, now stands for ... SOAP instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> XML-based protocol to exchange messages <soap:Body> <ns1:GetStockPrice xmlns:ns1="http://hauser-wenz.de/" Can be embedded in HTTP (but also in SMTP, ...) soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding"> <Stock xsi:type="xsd:string">PHP</Stock> </GetStockPrice> </soap:Body> </soap:Envelope> 27 June 2006 NYPHPCon 2006 Slide 19 27 June 2006 NYPHPCon 2006 Slide 20 Let‘s Have A Look (2) So, What Do You Think? A response HTTP/1.1 200 OK Good: Content-Type: text/xml; charset=utf-8 » Very flexible Content-Length: 1234 » Very mighty (including user-defined <?xml version="1.0" encoding="utf-8"?> data types) <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema- » Sanctioned by W3C instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> » Most software vendors agree on SOAP <soap:Body> <ns1:GetStockPriceResponse xmlns:ns1="http://hauser- Bad: wenz.de/" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding"> » Not quite lightweight <Price xsi:type="xsd:string">$42.00</Price> </GetStockPriceResponse> » Possibly bad data/information ratio </soap:Body> </soap:Envelope> 27 June 2006 NYPHPCon 2006 Slide 21 27 June 2006 NYPHPCon 2006 Slide 22 WSDL Let‘s Have A Look Lots of A WSDL description <?xml version="1.0" encoding="uft-8"?> namespaces ... „Web Services Description <definitions name="WebService" Language“ xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap" Messages xmlns:tns="http://hauser-wenz.de/WebService.wsdl" Describes the service xmlns:xsd="http://www.w3.org/2001/XMLSchema"> (input/output) <message name="GetStockPrice"> » Methods <part name="Stock" type="xsd:string"/> </message> » Parameters <message name="GetStockPriceResponse"> <part name="Price" type="xsd:string"/> Port (with » Return values </message> <portType name="QuotePortType"> operations) » Data types <operation name="GetStockQuote"> <documentation>Retrieve current stock quote of a company submitted as » Location of service parameter</documentation> <input message="tns:GetStockPrice" /> <output message="tns:GetStockPriceResponse" /> </operation> </portType> 27 June 2006 NYPHPCon 2006 Slide 23 27 June 2006 NYPHPCon 2006 Slide 24
    • Let‘s Have A Look (2) Let‘s Have A Look (3) A WSDL description (cont‘d) A WSDL description (cont‘d) <binding name="WebServiceSoap" type="tns:QuotePortType"> Bindings (rules <service name="WebService"> <soap:binding for data transfer) <port name="WebServiceSoap" Which services, transport="http://schemas.xmlsoap.org/soap/http"/> binding="wsdlns:WebServiceBinding"> <operation name="GetStockPrice"> <soap:address where? <soap:operation soapAction="http://hauser- wenz.de/webservice.php"/> location="http://www.hauser- wenz.de/webservice.php"/> <input> </port> <soap:body use="literal" /> </input> </service> <output> </definitions> <soap:body use="literal" /> </output> This looks rather messy! </operation> » Automatisms do prove really helpful </binding> here 27 June 2006 NYPHPCon 2006 Slide 25 27 June 2006 NYPHPCon 2006 Slide 26 UDDI Agenda „Universal Description, Discovery, and Integration“ A: Web Services – The Idea Provide „Yellow Pages“ for web services (and more) Web services information is stored in UBRs – Universal B: Web Services – The Standards Business Registries – that may be queried using a C: Web Services in PHP standardized API Various URBs synchronize (D: Wish List) » Microsoft, IBM, SAP, HP, NTT, ... Unfortunately, most test registries have been recently shut down 27 June 2006 NYPHPCon 2006 Slide 27 27 June 2006 NYPHPCon 2006 Slide 28 Web Services With PHP XML-RPC XML-RPC For PHP Well, you can do it manually! » Homepage: http://phpxmlrpc.sourceforge.net/ » It‘s just XML and all standardized ☺ » Widely used, after some stalling, development is up to speed again (but look at CVS!) However, there are modules that PEAR::XML_RPC come in really handy! » Homepage: http://pear.php.net » On some web pages /package/XML_RPC » In PEAR » Port of XML-RPC for PHP » In PHP itself XML-RPC Client/Server » Homepage: http:// keithdevens.com/software/xmlrpc » Still in active development » Version 3.0 exclusively for PHP5 27 June 2006 NYPHPCon 2006 Slide 29 27 June 2006 NYPHPCon 2006 Slide 30
    • SOAP SOAP (2) NuSOAP ext/soap a.k.a. PHP5-SOAP » Homepage: http://dietrich.ganx4.com/nusoap/ » Homepage: http://php.net/manual/en/ref.soap.php » LGPL-rewrite of SOAPx4 » New SOAP extension for PHP5 » Quite easy to use (if you use PHP4) » Written in C, so much faster than PEAR::SOAP » Can create WSDL automatically » However, still lacks a bit the stability of PEAR::SOAP PEAR::SOAP » Still some problems » Homepage: http://pear.php.net/package/SOAP » No built-in WSDL generation » Also based on SOAPx4 » But in the future the most promising extension » Under PHP4, the de-facto reference SOAP implementation 27 June 2006 NYPHPCon 2006 Slide 31 27 June 2006 NYPHPCon 2006 Slide 32 UDDI Demo Time! PEAR::UDDI Using XML-RPC » Homepage: http://pear.php.net/package/UDDI Using NuSOAP » Supports the inquiry API of UDDI 2.0 » Publish API is in the works Using PEAR::SOAP » LGPL-port of PHPUDDI to PEAR Using PHP5-SOAP Using PEAR::UDDI 27 June 2006 NYPHPCon 2006 Slide 33 27 June 2006 NYPHPCon 2006 Slide 34 Why So Complicated? Why REST? Very simple Often, REST is "good enough" PHP (5) offers great XML support REpresentational State Transfer » Especially SimpleXML comes in handy » PhD thesis of Roy Fielding, co-author of the HTTP specification Less error-prone than anything else Use HTTP for the request (parameters via GET) Good support from popular web services Retrieve XML via HTTP as the response » Amazon, Yahoo!, Google, ... Yep, that´s it. Every search engine uses REST, more or less » http://www.google.com/search?q=REST » http://a9.com/REST 27 June 2006 NYPHPCon 2006 Slide 35 27 June 2006 NYPHPCon 2006 Slide 36
    • Why not REST? Yahoo! Web Services You have to take care of object serialization Demo time! Hard(er) to implement security » Calling Yahoo! Web Service using REST & SimpleXML There is no such thing as REST-WSDL » Add some AJAX to the mix ... More request/response approach than demanded by SOA activists 27 June 2006 NYPHPCon 2006 Slide 37 27 June 2006 NYPHPCon 2006 Slide 38 Agenda A: Web Services – The Idea B: Web Services – The Standards C: Web Services in PHP (D: Wish List) 27 June 2006 NYPHPCon 2006 Slide 39 WSDL Generation With PHP5-SOAP There are options! » Services_Webservice (now in PEAR) Thank You! http://thinkforge.org/projects/wsdlgen/ » Ctrx_SOAP_AutoDiscover http://crtx.org/index.php?page=CrtxSoapAutoDiscover Questions? » Webservice Helper tool http://jool.nl/new/index.php?file_id=1 » WSDL_Gen http://www.hauser-wenz.de/ http://www.schlossnagle.org/~george/php/WSDL_Gen.tgz http://www.hauser-wenz.de/blog/ http://php.phrasebook.org/ 27 June 2006 NYPHPCon 2006 Slide 41 27 June 2006 NYPHPCon 2006 Slide 42