php soap usage

WBOY
Release: 2016-08-08 09:27:32
Original
1689 people have browsed it

Preparation:

Be prepared before using soap. Create a file in the www directory and add the following content under the file.

<?php echo phpinfo();?>
Copy after login
run this file to see if there is a soap module. If not, open the php.ini file. , remove the ; in front of
extension=php_soap.dll
Copy after login

, and restart apache.

Client:

Create a new php file in the www directory, the file name is client.php, add the following content under the file

<?php 
	$client = new SoapClient(null, array(&#39;location&#39; => "http://www.samples.com/Service.php",//服务端的文件位置
                                     'uri'=> "","login" => "outsider","password" => "1234567"//访问服务端文件时的用户名和密码));
	$user_info = json_decode($client->user_info());//服务端的方法
	$result = $client->show(1,3);//服务端的方法
	print_r($user_info->email.".....".$result);

?>
Copy after login
Server:

Create a new php file in the www directory, the file name Service.php, add the following content under this file

<?php
if (!isset($_SERVER[&#39;PHP_AUTH_USER&#39;]) || !isset($_SERVER[&#39;PHP_AUTH_PW&#39;]) ||
        !($_SERVER[&#39;PHP_AUTH_USER&#39;] == &#39;outsider&#39; && $_SERVER[&#39;PHP_AUTH_PW&#39;] == &#39;1234567&#39;)) {
    header(&#39;WWW-Authenticate: Basic realm="WEBSERVICE"&#39;);
    header("HTTP/1.0 401 Unauthorized");
    echo "You must enter a valid login ID and password to access this resource/n";
    die;
}//验证用户名和密码
class fuck{
function show($one, $two) {
        return $one + $two;
    }
 
    function user_info() {
        $user_info = array(
            &#39;name&#39; => 'Outsider',
            'sex' => '男',
            'email' => 'outsider@outsiderla.me',
            'tel' => '1369*******',
        );
        return json_encode($user_info);
    }
}
$server = new SoapServer(null, array('uri' => '', 'location' => 'http://www.samples.com/soapService.php'));
$server->setClass('fuck');//注册fuck类
$server->handle();
?>
Copy after login
. This way, the server and client are finished. Now access the client. The result is
outsider@outsiderla.me....4

The above introduces the usage of php soap, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template