: This article mainly introduces the WebService-php-1 (16), for PHP tutorials interested in students can refer to it. Recently I have read a lot of documents about webservice in php. thanks to the sharing of Yan 18, it helped me build the server. The learning notes are recorded as follows, including the notes of Yan 18.
WebService
1. quick introduction to WebService
In general, the remote server method is called in a certain XML format, and the server returns XML content in a certain format.
"A certain format" ---- SOAP (Simple Object Access Protocol) Simple Object Access Protocol is a Simple Protocol for exchanging information in a distributed or distributed environment. it is an XML-based Protocol.
Discussion.
Remote server-messages are generally transmitted over HTTP.
Conclusion: WebServie = XML in HTTP + Soap format
Example 1: soap request
POST/WebServices/MobileCodeWS. asmx HTTP/1.1
Host: webservice.webxml.com.cn
Content-Type: text/xml; charset = utf-8
Content-Length: 354
SOAPAction: "http://WebXml.com.cn/getMobileCodeInfo"
And restart apache
PHP SoapClient class can be used to request WebService
$soap = new soapClient('http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx?WSDL');print_r($soap->getMobileCodeInfo( array('mobileCode'=>'13**********') ) );
Array([0] => getMobileCodeInfoResponse getMobileCodeInfo(getMobileCodeInfo $parameters)[1] => getDatabaseInfoResponse getDatabaseInfo(getDatabaseInfo $parameters))Array([0] => struct getMobileCodeInfo {string mobileCode;string userID;}[1] => struct getMobileCodeInfoResponse {string getMobileCodeInfoResult;}[2] => struct getDatabaseInfo {}[3] => struct getDatabaseInfoResponse {ArrayOfString getDatabaseInfoResult;}[4] => struct ArrayOfString {
String;
}
// Call method print_r ($ soap-> getMobileCodeInfo (array ('lelecode' => '20140901 ')));
Returned results
StdClass Object ([getMobileCodeInfoResult] => 13 **********: Beijing Mobile phone motion zone card)
3. construct a WebService server
What is wsdl?
Wsdl is the specification of WebService.
The above introduces WebService-php-1 (16), including some content, and hope to be helpful to friends who are interested in PHP tutorials.