PHP中如何调用webservice的实例参考
下面用一个例子说明:web service服务是查询QQ用户是否在线
使用php5开发客户端:
复制代码 代码如下:
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("
");
var_dump($client->__getTypes());
print("
");
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;
}
?>
代码确实很简单吧,创建SoapClient对象时,可以使用保存在本地WSDL文件,也可以使用远程的地址,后面的array数组里可以带上很多的参数,具体参数可以查php的SoapClient帮助,这里带的是字符集编码,如果调用方法的参数里有中文,一定要指定字符集编码,否则会出错。
调用web service前可以先调用SoapClient的__geunctions()和__getTypes()方法看一下你要调用的web service暴露的方法,参数和数据类型,需要注意的是传入的参数名一定要和soapclient里面定义的一致,否则参数是传不过去的。
需要使用SoapClient的__soapCall()或__call()方法,具体使用方法可以查php的帮助文档。如果参数要求是一个结构体,请用类代替,如上面的代码。
另外发现个问题,如果web service方法返回的是xml格式的字符串,php接收到以后会自己把数据内容解析出来,而不是xml字符串.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Validator can be created by adding the following two lines in the controller.
