Getting parameter names from SOAP request with PHP SOAP extension?

Given that the following client.php creates this XML request:

<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://soap.dev/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <SOAP-ENV:Body> <ns1:Test> <RequestId xsi:type="xsd:int">1</RequestId> <PartnerId xsi:type="xsd:int">99</PartnerId> </ns1:Test> </SOAP-ENV:Body> </SOAP-ENV:Envelope> 

How do I access parameter names? (RequestId and PartnerId) inside server.php? Names are clearly present in the payload, but only values ​​are accepted on the server side (1 and 99)

Code example:

client.php

 <?php $client_params = array( 'location' => 'http://soap.dev/server.php', 'uri' => 'http://soap.dev/', 'trace' => 1 ); $client = new SoapClient(null, $client_params); try { $res = $client->Test( new SoapParam(1, 'RequestId'), new SoapParam(99, 'PartnerId') ); } catch (Exception $Ex) { print $Ex->getMessage(); } var_dump($client->__getLastRequest()); var_dump($client->__getLastResponse()); 

server.php

 class receiver { public function __call ($name, $params) { $args = func_get_args(); // here $params equals to array(1, 99) // I want the names as well. return var_export($args, 1); } } $server_options = array('uri' => 'http://soap.dev/'); $server = new SoapServer(null, $server_options); $server->setClass('receiver'); $server->handle(); 

Please note that I cannot change the format of the incoming request.

In addition, I know that I could return the names to the parameters by creating a test function with the parameters $RequestId and $PartnerId .

But I really want to get name / value pairs from the incoming request.

So far, the only idea I have is to just parse the XML, and that may not be right.

+4
source share
1 answer

Back when I had this problem, I finally decided to go with the idea of ​​a proxy function - check out a function with parameters with a name ($ RequestId and $ PartnerId) to return the names to the parameters. Its an adequate solution, but, of course, not the best.

I have not lost hope of finding a better solution, and here is my best idea so far

 <?php class Receiver { private $data; public function Test () { return var_export($this->data, 1); } public function int ($xml) { // receives the following string // <PartnerId xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xsd:int">99</PartnerId> $element = simplexml_load_string($xml); $this->data[$element->getName()] = (string)$element; } } $Receiver = new Receiver(); $int = array( 'type_name' => 'int' , 'type_ns' => 'http://www.w3.org/2001/XMLSchema' , 'from_xml' => array($Receiver, 'int') ); $server_options = array('uri' => 'http://www.w3.org/2001/XMLSchema', 'typemap' => array($int), 'actor' => 'http://www.w3.org/2001/XMLSchema'); $server = new SoapServer(null, $server_options); $server->setObject($Receiver); $server->handle(); 

This still means parsing the XML manually, but one element at a time, which is a little smarter than parsing the entire incoming SOAP message.

+1
source

All Articles