Example of PHP calling WebService

Source: Internet
Author: User
For everyone to introduce a PHP call WebService example, query QQ users online, have the need for friends, you can refer to the next.

Example, PHP developed by the client program called WebService.

 
      ' UTF-8 '); $client = new SoapClient ("http://webservice.webxml.com.cn/webservices/qqOnlineWebService.asmx?wsdl"); Var_dump ($client->__getfunctions ());p rint ("
"), Var_dump ($client->__gettypes ());p rint ("
"), class Qqcheckonline{var $qqCode =" 10000 ";}; $arrPara = Array (new Qqcheckonline), $arrResult = $client->__call ("Qqcheckonline", $arrPara);//$client Qqcheckonline ($arrPara); Echo $arrResult->qqcheckonlineresult. "
";} catch (SoapFault $e) {print $e;}? >

Description: When creating the SoapClient object, can be saved in the local WSDL file, you can use the remote address, the following array can take a lot of parameters, the specific parameters can be found in PHP soapclient help, here with the character set encoding, If you have Chinese in the parameters of the calling method, be sure to specify the character set encoding, or else an error will occur.

Before invoking the Web service, you can call SoapClient's __geunctions () and __gettypes () methods to see the methods, parameters, and data types that you want to invoke for the Web service exposure, It is important to note that the parameter names passed in must be consistent with the definitions in the SoapClient, otherwise the parameters will not pass through.

You need to use SoapClient's __soapcall () or __call () method to check the PHP Help documentation. If the parameter requirement is a struct, replace it with a class, such as the code above.

Issue: If the Web service method returns an XML-formatted string, PHP will then parse the data itself, rather than the XML string, when it receives it. In the practical application, we should pay more attention to this point.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.