Question

Actually I create a Soap Proxy in which I get the client request and I need to post the request further to another SOAP server (with c_url).

The response is successfully obtained (as xml with <SOAP-ENV and all others).

The problem is that in my SOAP PROXY I want to return exactly the response and if my server is returning the xml the SOAP Server actually return the XML file wrap up

<SOAP-ENV:Envelope ...>
   <SOAP-ENV:Body>
      <ns1:loginResponse>
        my xml that already contains <soap:Envelope, <soap:Body> and <namesp1:loginResponse>
      </ns1:loginResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

The question is: How can I make the soap server to return exactly the response that i want without wrapping up with soap envelope and others?

Thanks.

UPDATED:

My soap server:

$server = new SoapServer($myOwnWsdlPath);
$this->load->library('SoapProxy');
$server->setClass('SoapProxy', $params );
$server->handle();

My soap Porxy with c_url:

public function __call($actionName, $inputArgs)
{
//some logic

$target = ...
$url = ..
$soapBody =..
$headers = ..

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $soapBody); // the SOAP request
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$response = curl_exec($ch); //soap xml response
curl_close($ch);
    file_put_contents('/tmp/SoapCurl.txt', var_export($response, true));

return $response;

}

The response from /tmp/SoapCurl.txt is the correct one:

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope ...>
    <soap:Body>
        <namesp1:loginResponse>
            <session_id xsi:type="xsd:string">data</session_id>
        </namesp1:loginResponse>
    </soap:Body>
</soap:Envelope>

My soap server response is wrong:

<SOAP-ENV:Envelope ...>
   <SOAP-ENV:Body>
      <ns1:loginResponse>

         <soap:Envelope ...>
            <soap:Body>
               <namesp1:loginResponse>
                  <session_id xsi:type="xsd:string">correct data</session_id>
               </namesp1:loginResponse>
            </soap:Body>
         </soap:Envelope>

      </ns1:loginResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Was it helpful?

Solution

The fix I found was to extend the 'handle' function of SoapServer

Discard the output of SoapServer (with ob_end_clean) and replace it with my data

class MySoapServer extends SoapServer
{
    public function handle($soap_request = null)
    {
        parent::handle();
        ob_end_clean();
        ob_start();
        echo $_SESSION['data'];

    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top