Web Service FOR XML applications

Source: Internet
Author: User
Tags soap wsdl

1. What is a Web service?

Service: Services, install a software (program) on the computer, can provide us with certain functions, we can call it service. Local services are much more.

Web: And the local counterpart, on the Internet.

Web Service, through the Internet to provide some kind of services, the essence is to call other sites through the network resources.

Defects in local services:

(1) Insufficient local resources; Lots of data and information are not available locally, only to other websites.

(2) Cost factors; Local service delivery is often not economical, and the use of professional Web sites is cheaper.

(3) The portability is poor.

Benefits of WEB Service:

(1) Platform-Independent. No matter what platform you use, you can use Web service.

(2) programming language Independent. Web service can be implemented in any programming language, as long as the relevant protocol is adhered to.

(3) For Web service providers, deploying, upgrading, and maintaining Web service is simple

(4) For Web service users, it is easy to implement a variety of data, multiple services Aggregation (mashups), so you can make some things that were never imagined.

2.WEB Service Core Technology Introduction (1). Soap

SOAP:Simple Object Access Protocol, Simple Object Access protocol.

SOAP = XML + HTTP

(2). Wsdl

Web Service Description language:web Service Description Language.

In short, it is an XML document.

Using a Web service requires the extension to be opened in PHP's config file php.ini, as follows

Remove the front points to

3. Implement a flight query using a Web service (1). Where's the service?

Http://www.webxml.com.cn/zh_cn/web_services.aspx

The site also offers some other Web services, with Flight enquiry service as an example

WSDL, in fact, is an XML document, as follows:

Provides a number of methods that let us call in order to get flight information

Click to enter, as follows

The specific implementation code is as follows:

<! DOCTYPE html Public"-//w3c//dtd XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >#3195d3; border-collapse:collapse;}. airline th{height:35px; line-height:35px; border:1px Solid#e2e2e2; font-weight:bold; background: #3195D3; color: #fff;}. airline td{height:28px; line-height:28px; border:1px Solid#e2e2e2; text-align:center; background: #F5FCFF;}</style>PHP//instantiate a SoapClient object    $client=NewSoapClient ("http://ws.webxml.com.cn/webservices/DomesticAirline.asmx?wsdl"); $cities=$client-getdomesticcity (); $city=$cities->getdomesticcityresult->any ; $sxe=NewSimpleXMLElement ($city); $cityarr=Array(); foreach($sxe->children ()->children () as $child){           $cityarr[] =$child-Cncityname; }    //Check Flights    if(isset($_post[' button '])){        $startCity=$_post[' Fromcity ']; $lastCity=$_post[' Tocity ']; $theDate=$_post[' Date ']; $param=Array(            ' Startcity ' =$startCity, ' lastcity ' =$lastCity, ' thedate ' =$theDate, ' userID ' = '        ); $res=$client->getdomesticairlinestime ($param); $airline=$res->getdomesticairlinestimeresult->any ; $sxe=NewSimpleXMLElement ($airline); $airlinearr=Array(); foreach($sxe->children ()->children () as $child){            $airlinearr[] =$child; }    }><table width= "80%" border= "0" align= "center" cellpadding= "0" cellspacing= "0" > <tr> &LT;TD&GT;&A mp;nbsp;</td> </tr> <tr> <td align= "center" > <a href= "http://www.webxml . com.cn/"target=" _blank "></a><strong>Flight Schedules Web Service instances</strong> </td> </tr> <tr> <td>&nbsp;</td> </tr> & lt;tr> <td> <form name= "Form1" method= "Post" action= "" Id= "Form1" > < Table width= "100%" border= "0" cellspacing= "0" cellpadding= "0" > <tr> &lt TD style= "width:50%;" >Departure City<select name= "Fromcity" > <?phpforeach($cityarr  as $v):?> <option value= "<?php Echo$v;? > "><?phpEcho $v;? ></option> <?phpEndforeach;? > </select> &nbsp;&nbsp;&nbsp; arrive at the city<select name= "Tocity" > <?phpforeach($cityarr  as $v):?> <option value= "<?php Echo$v;? > "><?phpEcho $v;? ></option> <?phpEndforeach;? > </select> &nbsp;&nbsp;&nbsp; <label for= "CheckBox1" > Toggle City </label> &nbsp;&nbsp;&nbsp; </td> <td valign= "Middle" >Date<input name= "Date" value= "2014-12-20" type= "text" maxlength= "ten" size= "ten" id= "date"class= "Input1"/> &nbsp;&nbsp;&nbsp; <input type= "Submit" name= "button" value= "Query" id= "button"class= "Input2"/></td> </tr> </table> </fo rm> </td> </tr> <tr> <td>&nbsp; </td> </tr> <tr> <td> <table width= "100 % "border=" 0 "cellpadding=" 2 "cellspacing=" 1 "class= "Airline" > <tr> <th> Airlines </th> <th> Flight number </th> <th> departure Airport </th> <th& GT, departure time </th> <th> arrival Airport </th> <th> arrival time &LT;/TH&G                            T                        <th> models </th> <th> stops </th> </tr> <?phpforeach($airlinearr  as $v):?> <tr> &LT;TDclass= "tdbg" ><?phpEcho $v->company;? ></td> &LT;TDclass= "tdbg" ><?phpEcho $v->airlinecode;? ></td> &LT;TDclass= "tdbg" ><?phpEcho $v->startdrome;? ></td> &LT;TDclass= "tdbg" ><?phpEcho $v->starttime;? ></td> &LT;TDclass= "tdbg" ><?phpEcho $v->arrivedrome;? ></td> &LT;TDclass= "tdbg" ><?phpEcho $v->arrivetime;? ></td> &LT;TDclass= "tdbg" ><?phpEcho $v->mode;? ></td> &LT;TDclass= "tdbg" ><?phpEcho $v->airlinestop;? ></td> </tr> <?phpEndforeach;? > </table> </td> </tr> </table></body>& Lt;/html>

The query results are as follows:

Web Service FOR XML applications

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.