As per the title, is it possible to output the XML that a new SoapClient
has created before trying to run a __soapCall()
to ensure it's correct before actually sending it to the SOAP server?
In PHP to check whether SOAP enabled or not use built in function class_exists() : var_dump(class_exists("SOAPClient")); It also could be user to check any of modules classes.
To make SOAP requests to the SOAP API endpoint, use the "Content-Type: application/soap+xml" request header, which tells the server that the request body contains a SOAP envelope. The server informs the client that it has returned a SOAP envelope with a "Content-Type: application/soap+xml" response header.
A PHP SOAP Extension can be used to provide and consume Web services. In other words, this PHP extension can be used by PHP developers to write their own Web Services, as well as to write clients to make use of the existing Web services.
The soap:encodingStyle attribute determines the data types used in the file, but SOAP itself does not have a default encoding. soap:Envelope is mandatory, but the next element, soap:Header , is optional and usually contains information relevant to authentication and session handling.
You could use a derived class and overwrite the __doRequest() method of the SoapClient class.
<?php
//$clientClass = 'SoapClient';
$clientClass = 'DebugSoapClient';
$client = new $clientClass('http://www.webservicex.com/CurrencyConvertor.asmx?wsdl');
$client->sendRequest = false;
$client->printRequest = true;
$client->formatXML = true;
$res = $client->ConversionRate( array('FromCurrency'=>'USD', 'ToCurrency'=>'EUR') );
var_dump($res);
class DebugSoapClient extends SoapClient {
public $sendRequest = true;
public $printRequest = false;
public $formatXML = false;
public function __doRequest($request, $location, $action, $version, $one_way=0) {
if ( $this->printRequest ) {
if ( !$this->formatXML ) {
$out = $request;
}
else {
$doc = new DOMDocument;
$doc->preserveWhiteSpace = false;
$doc->loadxml($request);
$doc->formatOutput = true;
$out = $doc->savexml();
}
echo $out;
}
if ( $this->sendRequest ) {
return parent::__doRequest($request, $location, $action, $version, $one_way);
}
else {
return '';
}
}
}
prints
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.webserviceX.NET/">
<SOAP-ENV:Body>
<ns1:ConversionRate>
<ns1:FromCurrency>USD</ns1:FromCurrency>
<ns1:ToCurrency>EUR</ns1:ToCurrency>
</ns1:ConversionRate>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
NULL
But you'd have to change the actual code a bit for this to work which I try to avoid when possible (i.e. let tools do the work).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With