0

我已经使用下面的代码实现了一个 zend soap 服务器。出于我的目的,我需要能够访问完整的 XML 消息或至少它的标头。但是,SoapServer 上的 getLastRequest 方法返回空,并且所有超级全局变量,例如 $_GET、$_POST 等,也是空的。有人有什么想法吗?

class SoapTest
{

    protected $server;

    public function __construct(\Zend\Soap\Server $server)
    {
        $this->server = $server;    
    }

    /***
     * @param string $requestIn
     * @return string
     */
    public function test($requestIn)
    {
       // access XML here
    }
}
$serverUrl = "http://localhost/SoapTest.php";
    $options = [
        'uri' => $serverUrl,
    ];
    $server = new Zend\Soap\Server(null, $options);

    if (isset($_GET['wsdl'])) {
        $soapAutoDiscover = new \Zend\Soap\AutoDiscover(new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeSequence());
        $soapAutoDiscover->setBindingStyle(array('style' => 'document'));
        $soapAutoDiscover->setOperationBodyStyle(array('use' => 'literal'));
        $soapAutoDiscover->setClass(SoapTest::class);
        $soapAutoDiscover->setUri($serverUrl);

        header("Content-Type: text/xml");
        echo $soapAutoDiscover->generate()->toXml();
    } else {
        $soap = new \Zend\Soap\Server($serverUrl . '?wsdl', array('cache_wsdl' => WSDL_CACHE_NONE));
        $soap->setObject(new \Zend\Soap\Server\DocumentLiteralWrapper(new SoapTest($soap)));
        $soap->handle();
    }
4

1 回答 1

0

显然,Zend Soap Server 在句柄之后填充了 $request 属性(在 getLastRequest 中返回),所以我无法在我的方法中访问它。

但是,我可以通过调用以下命令来访问 XML:

$request = file_get_contents('php://input');
于 2018-01-18T09:54:32.530 回答