How do I call an instance reference for webservice in PHP

  • 2020-05-30 19:45:44
  • OfStack

Here is an example: the web service service is to find out if the QQ user is online

Developing clients using php5:


<?php
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;
}
?>

Code is very simple, create SoapClient object, you can use the stored in the local WSDL files, you can also use the remote address, at the back of the array array can bring a lot of parameters, a specific parameter can check php SoapClient help, here is the character set encoding, if the calling method of the parameters of Chinese, one must specify the character set encoding, otherwise it will go wrong.

You can call SoapClient's s 20en () and s 21en () methods first before calling web service, depending on the parameters and data types of the web s 23en exposed methods you are going to call. Be careful that the incoming parameter name 1 must correspond to the 1 defined in soapclient, otherwise the parameters will not be passed.

S 27en's s 28en () or s 29en's 29en () method will be used. Please refer to s 30en's help document. If the parameter requirement is 1 struct, use the class instead, as shown in the code above.

Another problem is that if the web service method returns a string in xml format,php will parse out the data itself instead of the xml string.


Related articles: