WebService - Obtener el XML que envia y recibe
#1
Escrito 29 enero 2012 - 03:07
http://www.delphiacc...e-y-tremotable/
Lo que necesito ahora, y le he dado muchas vueltas, es como puede obtener el XML de Request y Response del webservice. Puede ser desde la parte cliente o desde la parte servidor.
Me refiero a poder leerlo ya que tengo algun problema con clientes que lo consumen desde php y quería comparar lo que me llega desde php con lo que me llega desde un cliente delphi que funciona correctamente.
Gracias de antemano.
#2
Escrito 30 enero 2012 - 01:53
Me baje esta utilidad que permite hacer snifer de http:
http://www.ieinspect...yzer/index.html
De todas formas, si alguien sabe como leerlo directamente desde el ws de delphi que nos ilustre. Por el saber no ocupa lugar y desocupa mucho tiempo.
Un saludo.
#3
Escrito 16 febrero 2012 - 11:00
Desde un cliente hecho en delphi funciona correctamente y si en el servidor desactivo el control de la clave en la cabecera funciona desde delphi y desde php.
Este es el xml que envia el cliente delphi:
<?xml version="1.0" ?> <SOAP-ENV:Envelope 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:Header SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:NS1="urn:PadronServizoImpl"> <NS1:TSecurityHeader xsi:type="NS1:TSecurityHeader"> <Identificacion xsi:type="xsd:string"> clave </Identificacion> </NS1:TSecurityHeader> </SOAP-ENV:Header> <SOAP-ENV:Body xmlns:NS2="urn:PadronServizoIntf-IPadronServizo" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:NS3="urn:PadronServizoIntf"> <NS2:getEmpadroado> <lista xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="NS3:TRexistro[1]"> <item href="#2" /> </lista> </NS2:getEmpadroado> <NS3:TRexistro id="2" xsi:type="NS3:TRexistro"> <tipo xsi:type="xsd:string">D</tipo> <documento xsi:type="xsd:string">99999999H</documento> <resposta xsi:type="xsd:string"></resposta> </NS3:TRexistro> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
y con este código php en el que trato de reproducir el xml anterior:
<?php
require_once('lib/nusoap.php');
$client = new nusoap_client( "http://www.aaaa.com/cgi-bin/Ws.dll/wsdl/IPadronServizo","wsdl");
$header = '
<TSecurityHeader xsi:type="TSecurityHeader">
<Identificacion xsi:type="xsd:string">
clave
</Identificacion>
</TSecurityHeader>
';
$client->setHeaders($header);
$body = '
<lista xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="TRexistro[1]">
<item href="#2" />
</lista>'.
'<TRexistro id="1" xsi:type="TRexistro">
<tipo xsi:type="xsd:string">D</tipo>
<documento xsi:type="xsd:string">99999999H</documento>
<resposta xsi:type="xsd:string"></resposta>
</TRexistro>';
$result = $client->call('getEmpadroado',$body);
if ($client->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
} else {
$err = $client->getError();
if ($err) {
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
echo '<h2>Result</h2><pre>';
print_r($result);
echo '</pre>';
}
}
echo '<h2>Request</h2>';
echo '<pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2>';
echo '<pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
?>
obtengo este resultado:
Request
POST /cgi-bin/eurocidadanWs2.dll/soap/IPadronServizo HTTP/1.0 Host: [url=http://www.verin.net]www.verin.net[/url] User-Agent: NuSOAP/0.9.5 (1.123) Content-Type: text/xml; charset=ISO-8859-1 SOAPAction: "urn:PadronServizoIntf-IPadronServizo#getEmpadroado" Content-Length: 1043 <?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/" xmlns:ns7700="urn:PadronServizoIntf-IPadronServizo"><SOAP-ENV:Header> <TSecurityHeader xsi:type="TSecurityHeader"> <Identificacion xsi:type="xsd:string"> clave </Identificacion> </TSecurityHeader> </SOAP-ENV:Header><SOAP-ENV:Body><ns7700:getEmpadroado xmlns:ns7700="urn:PadronServizoIntf-IPadronServizo"> <lista xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="TRexistro[1]"> <item href="#2" /> </lista> <TRexistro id="1" xsi:type="TRexistro"> <tipo xsi:type="xsd:string">D</tipo> <documento xsi:type="xsd:string">34726246H</documento> <resposta xsi:type="xsd:string"></resposta> </TRexistro> </ns7700:getEmpadroado> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
Response
HTTP/1.1 200 OK Connection: close Date: Thu, 16 Feb 2012 16:36:54 GMT Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET Content-Type: text/xml; charset="utf-8" Content-Length: 439 <?xml version="1.0"?> <SOAP-ENV:Envelope 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> <SOAP-ENV:Fault> <faultcode> SOAP-ENV:Server </faultcode> <faultstring> Clave Incorrecta </faultstring> <faultactor/> </SOAP-ENV:Fault> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
#4
Escrito 16 febrero 2012 - 11:28
xmlns:ns7700="urn:PadronServizoIntf-IPadronServizo"
deberías hacer esto:
<ns7700:TSecurityHeader xsi:type="TSecurityHeader">
<Identificacion xsi:type="xsd:string">
clave
</Identificacion>
</ns7700:TSecurityHeader>
Saludos
#5
Escrito 16 febrero 2012 - 12:00
Fault
Array
(
[faultcode] => SOAP-ENV:Server
[faultstring] => Referencia a un prefijo de espacio de nombres no declarado: 'ns7700'.
Line: 2
#6
Escrito 16 febrero 2012 - 12:03
El "ns7700" lo genera el php, no se lo meto yo. Si se lo pongo a pelo me dice:
Fault
Array
(
[faultcode] => SOAP-ENV:Server
[faultstring] => Referencia a un prefijo de espacio de nombres no declarado: 'ns7700'.
Line: 2
Ah caray, entonces debe ser dinámico, lamentablemente de PHP no te puedo decir mas.
Saludos
#7
Escrito 16 febrero 2012 - 02:13
#8
Escrito 19 febrero 2012 - 03:57
En vez de utilizar nusoap, que actualmente está descontinuado en php, he utilizado las clases nativas de php para soap:
http://www.php.net/m...s/book.soap.php
y el siguiente código:
<?php
$cliente = new soapclient( 'http://www.aaaa.com/cgi-bin/Ws.dll/wsdl/IPadronServizo',
array( 'trace' => 1,
'exceptions' => 1));
$cabeceiraCorpo = array('Identificacion' => 'clave');
$cabeceira = new SoapHeader("urn:PadronServizoImpl","TSecurityHeader" ,$cabeceiraCorpo);
$cliente->__setSoapHeaders(array($cabeceira));
$r1 = array(
'tipo' => 'D',
'documento' => '99999999H',
'resposta' => '');
$r2 = array(
'tipo' => 'T',
'documento' => 'X8888888E',
'resposta' => '');
$lista = array();
$lista[] = $r1;
$lista[] = $r2;
$corpo = new SoapParam($lista, 'lista');
print_r($corpo);
echo '<br><br>';
$result = $cliente->getEmpadroado($corpo);
print_r($result);
echo '<h2>Request</h2>';
echo '<pre>' . htmlspecialchars($cliente->__getLastRequest(), ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2>';
echo '<pre>' . htmlspecialchars($cliente->__getLastResponse(), ENT_QUOTES) . '</pre>';
?>
Espero que esto ayude a alguien en el futuro.