The following is an example: the web service service is to query whether QQ users are online
Use php5 to develop a client:
<?php
try {
//$client = new SoapClient("",array('encoding'=>'UTF-8'));
$client = new SoapClient("/webservices/?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;
}
?>
The code is indeed very simple. When creating a SoapClient object, you can use the local WSDL file to save it or use a remote address. The array behind can include a lot of parameters. You can check the SoapClient help in php. Here it contains character set encoding. If there is Chinese in the parameters of the calling method, you must specify the character set encoding, 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 name passed must be consistent with the definition in soapclient, otherwise the parameters cannot be passed.
You need to use the __soapCall() or __call() method of SoapClient. You can check the help documentation of php. If the parameter requires a structure, please use a class instead, as in the above code.
Another problem was found. If the web service method returns a string in XML format, PHP will parse the data content itself after receiving it, instead of the XML string.