PHP SOAP

<?php
$classmap = array();
//注意和实例一的不同
$soap = new SoapServer(null, array('uri' => "http://localhost", "classmap" => $classmap));
$soap->setClass('Myclass');
$soap->handle();
class Myclass
{
    function say($someword)
    {
        return $someword;
    }
}
?>
<?
try {
    $client = new SoapClient(null, array('location' => "http://localhost/server.php",
            'uri' => "http://localhost"));
    //var_dump($client);
    echo $client->say("xyz world");
}
catch (SoapFault $fault) {
    echo "Error: ", $fault->faultcode, ", string: ", $fault->faultstring;
}

Internal Server Error

表示服务器验证出错

<?php

// 服务器验证
if ($_SERVER['PHP_AUTH_USER'] != 'bo' || $_SERVER['PHP_AUTH_PW'] != 'bo') {
    header('WWW-Authenticate: Basic realm="MyFramework Realm"');
    header('HTTP/1.0 401 Unauthorized');
    echo "You must enter a valid login ID and password to access this resource.
";
    exit;
}

require ("soapHandle.class.php"); // 处理请求的class

try {
    $server = new SOAPServer(null, array('uri' => 'http://localhost/soap/server.php'));
    $server->setClass('soapHandle'); //设置处理的class
    $server->handle();
}
catch (SOAPFault $f) {
    print $f->faultString; // 打印出错信息
}

?>
<?php

class soapHandle{

    public function strtolink($url=''){
        return sprintf('<a href="%s">%s</a>', $url, $url);
    }

}

?>
<?php

try {
    $client = new SOAPClient(null, array(
        'location' => 'http://localhost/soap/server.php', // 设置server路径
        'uri' => 'http://localhost/soap/server.php',
        'login' => 'bo', // HTTP auth login
        'password' => 'bo' // HTTP auth password
            ));

    echo $client->strtolink('http://blog.csdn.net/fdipzone') . '<br>'; // 直接调用server方法
    echo $client->__soapCall('strtolink', array('http://blog.csdn.net/fdipzone')); // 间接调用server方法
}
catch (SOAPFault $e) {
    print $e->getMessage();
}

?>

<?php$classmap = array();//注意和实例一的不同$soap = new SoapServer(null, array('uri' => "http://localhost", "classmap" => $classmap));$soap->setClass('Myclass');$soap->handle();class Myclass{    function say($someword)    {        return $someword;    }}?>

原文地址:https://www.cnblogs.com/ilookbo/p/5721876.html