I am trying to make a client request for a soap web service, and when I try to create the xml with simplexml_load_string it says this:
Error: Cannot create object
With no any other errors, so I can't figure it out what am I doing wrong, my code is bellow, I hope you can help me to solve this issue
<?php
$produccion = false; //Cambiar a verdadero por producction
$url = "http://ws.maxirest.com/wsclientes/wscli06896.php";
//print_r($_POST);
$posts = $_POST;
if ($produccion == false) {
$posts['nombre'] =
$posts['apellido'] =
$posts['direccion'] =
$posts['pisodto'] =
$posts['localidad'] =
$posts['partido'] =
$posts['provincia'] =
$posts['telefono'] =
$posts['celular'] =
"PRUEBA";
}
$Datos = "<cliente>
<nombre>".$posts['nombre']."</nombre>
<apellido>".$posts['apellido']."</apellido>
<calle>".$posts['direccion']."</calle>
<altura>".$posts['altura']."</altura>
<pisodto>".$posts['pisodto']."</pisodto>
<localidad>".$posts['localidad']."</localidad>
<partido>".$posts['partido']."</partido>
<provincia>".$posts['provincia']."</provincia>
<telefono>".$posts['telefono']."</telefono>
<celular>".$posts['celular']."</celular>
<num_tarjeta>".$posts['num_tarjeta']."</num_tarjeta>
</cliente>";
$myXMLData = '<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.maxisistemas.com.ar">
<soapenv:Header/>
<soapenv:Body>
<ws:AltaSolicitud soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<cXml>'.$Datos.'</cXml>
<Clave>123ClubMilaMREST5</Clave>
</ws:AltaSolicitud>
</soapenv:Body>
</soapenv:Envelope>';
$xml=simplexml_load_string($myXMLData) or die("Error: Cannot create object"); //<-Here is the error
$client = new SoapClient($url);
$result1 = $client->AltaSolicitud($xml);
$result2 = $client->ConsultaPuntos($xml);
?>
答案 0 :(得分:1)
I can't get an answer but
=> "ERROR. ACCESO NO PERMITIDO"
But with the right credentials and data you should be able to get the information you need with below class.
Simply set your data in the setData()
function / call it first and then call AltoSolicitud() with Clave
as parameter
class Request extends \SoapClient
{
public $Datos;
public function __construct(array $options = [], $wsdl = 'http://ws.maxirest.com/wsclientes/wscli06896.php?wsdl')
{
$options = [
'features' => 1,
];
parent::__construct($wsdl, $options);
}
/**
* @param string $Clave
* @return string
*/
public function AltaSolicitud()
{
$Data = $this->getData();
try {
return $this->__soapCall('AltaSolicitud', [
$Data
]);
} catch (\SoapFault $e) {
return ($e->getMessage());
}
}
public function setData($posts,$produccion = false)
{
if ( ! $produccion) {
$posts['nombre'] =
$posts['apellido'] =
$posts['direccion'] =
$posts['pisodto'] =
$posts['localidad'] =
$posts['partido'] =
$posts['provincia'] =
$posts['telefono'] =
$posts['celular'] =
"PRUEBA";
}
$Datos = "<cliente><nombre>".$posts['nombre']."</nombre>
<apellido>".$posts['apellido']."</apellido>
<calle>".$posts['direccion']."</calle>
<altura>".$posts['altura']."</altura>
<pisodto>".$posts['pisodto']."</pisodto>
<localidad>".$posts['localidad']."</localidad>
<partido>".$posts['partido']."</partido>
<provincia>".$posts['provincia']."</provincia>
<telefono>".$posts['telefono']."</telefono>
<celular>".$posts['celular']."</celular>
<num_tarjeta>".$posts['num_tarjeta']."</num_tarjeta></cliente>";
$Clave = '123ClubMilaMREST5';
$myXMLData = <<<XML
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.maxisistemas.com.ar">
<soapenv:Header/>
<soapenv:Body>
<ws:AltaSolicitud soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<cXml xsi:type="xsd:string">' . str_replace(PHP_EOL,'',$Datos) . '</cXml>
<Clave xsi:type="xsd:string">' . $Clave . '</Clave>
</ws:AltaSolicitud>
</soapenv:Body>
</soapenv:Envelope>
XML;
$this->Datos = $myXMLData;
return $this;
}
/**
* @param string $Cod_Tarj
* @param string $Clave
* @return string
*/
public function ConsultaPuntos($Cod_Tarj, $Clave)
{
return $this->__soapCall('ConsultaPuntos', [$Cod_Tarj, $Clave]);
}
public function getData(){
return $this->Datos;
}
$request = (new Request)->setData($_POST,false)->AltaSolicitud();
var_dump($request);
答案 1 :(得分:1)
@Ricardo
我能够通过添加&#34; wsdl&#34;来使代码工作。到网址。在此更改后,我没有看到错误&#34;无法创建对象&#34;。
$url = "http://ws.maxirest.com/wsclientes/wscli06896.php?wsdl";
我做了一些其他的小改动,但我认为它们并不重要:
$xml = simplexml_load_string( $myXMLData ); //or die("Error: Cannot create object"); //<-Here is the error
$client = new SoapClient( $url , array('trace' => 1 ));
$result1 = $client->AltaSolicitud($xml);
echo "Response:\n" . $client->__getLastResponse() . "\n";
结果是相同的&#34;错误。 ACCESO NO PERMITIDO&#34;已经注意到了对我来说,似乎soap参数<Clave>123ClubMilaMREST5</Clave>
不正确或已过期。我注意到这一点,因为意大利语中的单词几乎相同(chiave = clave = key)。我认为这是许多Web服务需要的API密钥吗?
SOAP响应
<?xml version="1.0" encoding="ISO-8859-1"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 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:Body>
<ns1:AltaSolicitudResponse xmlns:ns1="http://ws.maxisistemas.com.ar">
<return xsi:type="xsd:string">ERROR. ACCESO NO PERMITIDO</return>
</ns1:AltaSolicitudResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>