首页 > 解决方案 > 在 PHP 的 SoapServer 中的 SetClass 之后添加 SoapHeader

问题描述

我有一个在 $obj->setClass() 中设置的类来处理 SoapServer 中的请求。但现在我需要在该类中设置一些soapHeader。我如何在该类中设置 SoapHeader 或访问 SoapServer 对象?

服务器.php

$svr = new SoapServer('http://localhost?wsdl');
$svr->setClass("SampleClass");
$svr->handle();

样本类

class sample { 
 public function test() { 
   // add some soapHeader to $svr object
 }
}

--编辑--找到了解决方案:)

只需在处理程序类函数中创建 $svr 全局并使用 addSoapHeader 。如果您在 svr object 中使用 addSoapHeader,它将被 ->handle() 覆盖。

class sample { 
 public function test() {  
global $svr;
$svr->addSoapHedaer($soapHeader); 
   // add some soapHeader to $svr object
 }
}

您需要在使用 SoapHeader PHP 本机类之前制作 $soapHeader

标签: phpsoapsoapheadersoapserver

解决方案


推荐阅读