Professional Documents
Culture Documents
08 - Web Service
08 - Web Service
LP TRNH WEB
L nh Thanh B mn Mng v Truyn thng My tnh Khoa Cng ngh Thng tin Trng i hc Cng ngh, HQGHN E-mail: thanhld@vnu.edu.vn, thanhld.vnuh@gmail.com Mobile: 0987.257.504
Bi 8
Web service
Ni dung
v = f(10)
WS Response
Application
Web Service
WSDL
Ti liu WSDL (Web Service Definition Language) c s dng xc nh cc phng thc m WS cung cp, c th triu gi qua mng Mi WS cn c mt ti liu WSDL m t v n
SOAP = HTTP + XML (thng bo SOAP l thng bo HTTP vi ni dung l ti liu XML c cu trc c SOAP quy nh)
r = f(10) SOAP WS request f(x) g(x, y) h(z)
SOAP WS response
SOAP WS
<?xml version="1.0" encoding="ISO-8859-1"?> <SOAP-ENV:Envelope SOAPENV:encodingStyle="http://schemas.xmlsoap.org/soap/e ncoding/" xmlns:SOAPENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance" xmlns:SOAPENC="http://schemas.xmlsoap.org/soap/encoding/"><SO AP-ENV:Body><ns2820:normalizeName xmlns:ns2820="http://tempuri.org"><name xsi:type="xsd:string"> hoang THu </name></ns2820:normalizeName></SOAPENV:Body></SOAP-ENV:Envelope>
To SOAP WS
Cho php m rng php_soap To th vin cc hm cho WS To ti liu WSDL m t v WS To SOAP WS
To th vin cc hm cho WS
<?php function normalizeName($name, $type) { $ss = explode(" ", $name); $ret = ""; for ($i = 0; $i < count($ss); $i++) { if (strcmp($ss[$i], "") != 0) { if (strcmp($ret, "") != 0) $ret .= " "; $ret .= $ss[$i]; } } if ($type == "UCW") return ucwords(strtolower($ret)); return ucfirst(strtolower($ret)); } function ageFromDoB($vd) { //$vd: dd/mm/yyyy $ss = explode("/", $vd); //tach xau $age = intval(date("Y")) - intval($ss[2]); return $age; } ?>
<message name="ageFromDoB_Parameters"> <part name="vndate" type="xsd:string"/> </message> <message name="ageFromDoB_Return"> <part name="age" type="xsd:string"/> </message>
L nh Thanh, Bi ging Lp trnh web.
To SOAP WS
<?php require_once("lib.php"); ini_set("soap.wsdl_cache_enabled", "0"); $server = new SoapServer("mywebservice.wsdl"); $server->addFunction("normalizeName"); $server->addFunction("ageFromDoB"); $server->handle(); ?>
Xem WSDL ca WS
NuSOAP
L SOAP toolkit dng cho pht trin SOAP server v SOAP client C th c s dng pht trin SOAP WS.
T hc
L nh Thanh, Bi ging Lp trnh web.
Nh mi gii to danh b WS
UDDI (Universal Description, Discovery and Integration)
Ht