How to invoke WebService instance reference _php techniques in PHP

Source: Internet
Author: User
Tags wsdl

The following is an example: Web service is to query whether QQ users online

Using PHP5 to develop clients:

Copy Code code as follows:

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


The code is really very simple, you can create a SoapClient object, save in the local WSDL file, you can use the remote address, the following array of arrays can take a lot of parameters, specific parameters can check PHP soapclient help, here with the character set code, If you have Chinese in the parameter of the calling method, be sure to specify the character set encoding, or you will get an error.

You can call the SoapClient __geunctions () and __gettypes () methods before calling the Web service to look at the methods, parameters, and data types of the Web service exposure you want to invoke. It is important to note that the incoming parameter names must be consistent with the definition in soapclient, otherwise the parameters are not passed.

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

The

also finds a problem, if the Web service method returns an XML-formatted string, and PHP receives its own parsing of the data, rather than an XML string.

Related Article

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.