public
Created

SoapClass

  • Download Gist
soap.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
<?php
ini_set("soap.wsdl_cache_enabled", "0");
ini_set("soap.wsdl_cache", "0");
ini_set("display_errors","On");
ini_set("track_errors","On");
 
class Soap
{
public $client;
public $login;
public $isSOAPAvailable = true;
public $response;
public $methodCall='';
public $parameters = array();
public $lastFailedURL = "";
public $lastURL = "";
function __contruct()
{
}
function init($url,$params=array())
{
if ($this->lastURL == $url) {
return true;
}
if(DEFAULT_SOAP_ENABLED) {
/*if(!$params[DEFAULT_SOAP_login_key])
$params[DEFAULT_SOAP_login_key] = DEFAULT_SOAP_login;
if(!$params[DEFAULT_SOAP_password_key])
$params[DEFAULT_SOAP_password_key] = DEFAULT_SOAP_password;*/
}
try
{
$this->lastURL = $url;
$time = microtime(true);
$this->client = new SoapClient(
$url. '&r=' . rand(10,1000),
array(
'SOAP' => SOAP_1_2,
"style" => SOAP_DOCUMENT,
'trace' => 1,
'encoding'=>'ISO-8859-1'
//"uri" => "urn:xmethods-delayed-quotes"
// "uri"=>"env:myWS"
));
$time = microtime(true) - $time;
}catch(Exception $e)
{
echo $e;
echo "<br />";
echo 'Error de Conexion';
echo $url;
echo "<br />";
echo "<br />";
exit;
$this->isSOAPAvailable = false;
}
if($this->client)return true;
else return false;
}
function SOAPMethod($name, $parameters=array())
{
$return_variable = false;
try
{
if($this->isSOAPAvailable)
{
// echo "calling";
$this->methodCall = $name;
$this->parameters = $parameters;
$time = microtime(true);
//echo 'Error se ejecuta [' . $name . ']';
//if ($name == 'ActualizaCuentasBancoOp')
 
$return_variable = $this->client->__soapCall($name,$parameters);
// echo 'Error se ejecuta [' . $name . ']';
$time = microtime(true) - $time;
$this->response = $return_variable;
$this->saveLog();
/*
echo 'WEB SERVICE METHOD CALL TIME "'.$name.'"[' . $time .' &micro;s]<br />';
echo '<strong>Last Request Headers:</strong> <br />';
echo $this->client->__getLastRequestHeaders();
echo '<br />';
echo '<br />';
echo '<strong>Last Response Headers:</strong> <br />';
echo $this->client->__getLastResponseHeaders();
echo '<br />';
echo '<br />';
echo '<br />';
echo '<strong>Last Response:</strong> <br />';
echo '<pre>';
echo htmlentities(formatXmlString($this->client->__getLastResponse()));
echo '</pre>';
echo '<br />';
echo '<br />';
echo 'aqui';
var_dump($return_variable);
echo 'aqui';
echo '<br />';
echo '<pre>';
var_dump($this->client);
echo '</pre>';
echo '<br />';
echo '<strong>Last Response:</strong> <br />';
echo htmlentities($this->client->__getLastResponse());
echo '<br />';
echo '<br />';
echo '<strong>Last Request:</strong> <br />';
echo '<pre>';
echo htmlentities(formatXmlString($this->client->__getLastRequest()));
echo '</pre>';
echo '<br />';
echo '<br />';
echo '<br />';
echo '<strong>Error:</strong> <br />'. $fault;
echo '<br />';
echo '<br />';
echo '<strong>Types:</strong> <br />';
echo '<pre>';
echo print_r($this->client->__getTypes());
echo '</pre>';
echo '<br />';
echo '<br />';
echo '<strong>Functions:</strong> <br />';
echo '<pre>';
echo print_r($this->client->__getFunctions());
echo '</pre>';
*/
}
else
{
echo 'Web Service no disponible';
}
}catch(SoapFault $fault) {
if (function_exists("errorHandler")) {
$error_string = "method : " + $name;
$error_string .= "\n";
$error_string .= "Last Request: ";
$error_string .= "<code>" .$this->client->__getLastRequest() . "</code>";
$error_string .= "Last Response: ";
$error_string .= "<code>" .$this->client->__getLastResponse() . "</code>";
$error_string .= "Fault: ";
$error_string .= "<code>" .$fault . "</code>";
//$error_number, $error_string, $error_file, $error_line, $error_context
errorHandler(666, $error_string, "SOAP FAULT -ERROR DE SERVICIOS-", __LINE__, $error_string);
}
$return_variable = array("failed" =>true);
}
return $return_variable;
}
function arrayToSOAPParameters($array)
{
$array_of_soap_objects = array();
foreach($array as $key => $value)
{
$array_of_soap_objects[] = new SoapParam
(
$value,
$key
);
}
return $array_of_soap_objects;
}
function saveLog($error=false)
{
if (!function_exists("formatXmlString")) {
return false;
}
$lastRequestHeaders = $this->client->__getLastRequestHeaders();
$lastResponseHeaders = $this->client->__getLastResponseHeaders();
$lastRequestBody = $this->client->__getLastRequest();
$lastResponseBody = $this->client->__getLastResponse();
$lastDataTypes = $this->client->__getTypes();
$lastFunctions = $this->client->__getFunctions();
$html = '<html>';
$html .= ' <head></head>';
$html .= ' <body>';
$html .= ' <div><strong>DATE:</strong>' . @date('Y-m-d H:i:s') . '</div>';
$html .= ' <div><strong>METHOD CALL:</strong>' . $this->methodCall . '</div>';
$html .= ' <div><strong>ARRAY PARAMETERS:</strong><br /><textarea style="width:100%;height:50px;">' . print_r($this->parameters,true) . '</textarea></div>';
$html .= ' <div><strong>LAST REQUEST HEADERS:</strong><br /><textarea style="width:100%;height:100px;">' . $lastRequestHeaders . '</textarea></div>';
$html .= ' <div><strong>LAST RESPONSE HEADERS:</strong><br /><textarea style="width:100%;height:100px;">' . $lastResponseHeaders . '</textarea></div>';
$html .= ' <div><strong>LAST REQUEST BODY:</strong><br /><textarea style="width:100%;height:100px;">' . htmlentities(formatXmlString($lastRequestBody)) . '</textarea></div>';
$html .= ' <div><strong>LAST RESPONSE BODY:</strong><br /><textarea style="width:100%;height:100px;">' . htmlentities(formatXmlString($lastResponseBody)) . '</textarea></div>';
$html .= ' <div><strong>LAST DATA TYPES:</strong><br/><textarea style="width:100%;height:100px;">' . $lastDataTypes . '</textarea></div>';
$html .= ' <div><strong>LAST FUNCIONS:</strong><br /><textarea style="width:100%;height:100px;">' . $lastFunctions . '</textarea></div>';
$html .= ' <div><strong>ARRAY RESPONSE:</strong><br /><textarea style="width:100%;height:100px;">' . print_r($this->response,true) . '</textarea></div>';
if($error)
{
$html .= ' <div><strong>ERROR:</strong><br /><textarea style="width:50%;height:100px;">' . $error . '</textarea></div>';
}
$html .= ' </body>';
$html .= '</html>';
$fh = @fopen( LOGS_SOAP . $this->methodCall . '.html', "wa+");
if($fh)
{
fputs( $fh, $html, strlen($html) );
fclose( $fh );
}
}
}
?>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.