Example of php calling webservice

WBOY
Release: 2016-07-25 08:59:47
Original
931 people have browsed it
Let me introduce to you an example of calling webservice in PHP to check whether QQ users are online. Friends in need can refer to it.

Example, calling webservice in a client program developed by PHP.

<?php
/**
 * php调用webservice
 * web service服务是查询QQ用户是否在线
 * by bbs.it-home.org
*/
try {
//$client = new SoapClient("HelloService.wsdl",array('encoding'=>'UTF-8'));
$client = new SoapClient("http://webservice.webxml.com.cn/webservices/qqOnlineWebService.asmx?wsdl");
var_dump($client->__getFunctions());
print("<br/>");
var_dump($client->__getTypes());
print("<br/>");

class qqCheckOnline{
var $qqCode = "10000";
};
$arrPara = array(new qqCheckOnline);

$arrResult = $client->__Call("qqCheckOnline",$arrPara);//$client->qqCheckOnline($arrPara);

echo $arrResult->qqCheckOnlineResult . "<br/>";
} catch (SOAPFault $e) {
print $e;
}
?>
Copy after login

Instructions: When creating a SoapClient object, you can use a WSDL file saved locally or a remote address. The following array can contain many parameters. For specific parameters, you can check the SoapClient help of php. Here is the character set encoding. If If there are Chinese characters in the parameters of the calling method, the character set encoding must be specified, otherwise an error will occur.

Before calling the web service, you can first call the __geunctions() and __getTypes() methods of SoapClient to see the methods, parameters and data types exposed by the web service you want to call. It should be noted that the parameter names passed in must be the same as soapclient The definitions inside are consistent, otherwise the parameters cannot be passed.

You need to use the __soapCall() or __call() method of SoapClient. For specific usage methods, you can check the PHP help documentation. If the parameter requirement is a structure, please use a class instead, such as the code above.

Question: If the web service method returns a string in XML format, PHP will parse the data content by itself after receiving it, instead of the XML string. Everyone should pay more attention to this in practical applications.



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!