什么不说直接上代码 soapserver.php <?php error_reporting(2047); ini_set("soap.wsdl_cache_enabled", "0"); class mysoapclass { private $Authenticated =FALSE; public function authenticate($value){ //$name =$value->item[0]->value; //$pwd =$value->item[1]->value; if($value->username == 'admin'&& $value ->password=='123456') { $this->Authenticated = true; } else { $this->Authenticated = FALSE; } } function feline(){ if($this->Authenticated){ return '成功'; } else { return '下次成功'; } } } $server = new SoapServer(null, array('uri' => 'http://test.cheshi.com')); $server->setClass('mysoapclass'); $server->handle(); ?> soapclient.php <?php ini_set("soap.wsdl_cache_enabled", "0"); class authentication_header { var $username; var $password; public function __construct($username, $password) { $this->username = $username; $this->password = $password; } } try { $auth = new authentication_header('admin', '123456'); $authvalues = new SoapVar($auth, SOAP_ENC_OBJECT, 'authenticate','http://test.cheshi.com'); //$authvalues =array('username'=>'admin','pwd'=>'123456'); $header = new SoapHeader('http://test.cheshi.com/', 'authenticate', $authvalues,true); //$client = new SoapClient('http://test.cheshi.com/webservice/soapserver.php?wsdl'); $client = new SoapClient(null, array('uri' => 'http://test.cheshi.com', 'location' => 'http://test.cheshi.com/webservice/soapserver.php', 'trace' => true)); $re=$client->__setSoapHeaders(array($header)); echo $result =$client->__soapCall('feline',array()); }catch (SoapFault $e){ echo $e->getMessage(); } ?>