Foros del Web » Programando para Internet » PHP »

Php, Webservices - curl y soap

Estas en el tema de Php, Webservices - curl y soap en el foro de PHP en Foros del Web. Hola, estoy tratando de consumir un webservice con curl, utilizando esta funcion: function soap_operation($host='http://192.168.0.105', $port = 443, $url='/Inventario.asmx', $action='http://tempuri.org/GetTopSellersFromCategory', $body,$products_model,$numero,$catego,$usarSemilla ) { $request = "'POST'"; ...
  #1 (permalink)  
Antiguo 26/07/2010, 11:53
 
Fecha de Ingreso: julio-2010
Mensajes: 2
Antigüedad: 13 años, 9 meses
Puntos: 0
Php, Webservices - curl y soap

Hola,

estoy tratando de consumir un webservice con curl, utilizando esta funcion:

function soap_operation($host='http://192.168.0.105', $port = 443, $url='/Inventario.asmx', $action='http://tempuri.org/GetTopSellersFromCategory', $body,$products_model,$numero,$catego,$usarSemilla )
{ $request = "'POST'";
require_once('lib/xml2array.php');
$eol = "\r\n";
// extract namespace from soap action
preg_match('/(http?:\/\/.*\/)(.*)/', $action, $matches) or die("Invalid SOAPAction: '$action'");
echo $soap_ns = $matches[1];
echo $soap_action = $matches[2];

// create soap envelope
// convert to utf8 and get the content length
$content ='<?xml version="1.0" encoding="utf-8"?>'.$eol;
$content .='<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'.$eol;
$content .='<soap:Body>'.$eol;
$content .='<'.$soap_action.' xmlns="'.$soap_ns.'">'.$eol;
$content .='<ASIN>'.$products_model.'</ASIN>'.$eol;
$content .='<NroArticulos>'.$numero.'</NroArticulos>'.$eol;
$content .='<CategoriaTraetelo>'.$catego.'</CategoriaTraetelo>'.$eol;
$content .='<UsarSemilla>'.$usarSemilla.'</UsarSemilla>'.$eol;
$content .='</'.$soap_action.'>'.$eol;
$content .='</soap:Body>'.$eol;
$content .='</soap:Envelope>';

$content = utf8_encode($content);
$content_length = strlen($content);

$headers = array(
"POST ".$url." HTTP/1.1",
"Host: ".str_replace("http://","",$host)."",
"Content-Length: ".$content_length." ",
"Content-Type: text/xml; charset=utf-8",
"Connection: close",
"SOAPAction: \"".$soap_ns.$soap_action."\"".$eol,
$content);
print_r($headers);
$ch = curl_init ($host.$url);
curl_setopt($ch, CURLOPT_URL, "http://192.168.0.102:81/Inventario.asmx?wsdl" );
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $request);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt ($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $content);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
$parser = new XMLParser($ch);
$parser->Parse();
return $parser;
} // End soap_operation()


Arojándome como error lo siguiente:
Notice: XML Parsing Error at 1:1. Error 4: Not well-formed (invalid token) in D:\Aplicaciones\Shop\includes\functions\lib\xml2ar ray.php on line 112

e imprimiendome por pantalla lo siguiente:

Array ( [0] => POST /Inventario.asmx HTTP/1.1 [1] => Host: 192.168.0.105:81 [2] => Content-Length: 477 [3] => Content-Type: text/xml; charset=utf-8 [4] => Connection: close [5] => SOAPAction: "http://tempuri.org/GetTopSellersFromCategory" [6] => AMB000E43GP8 5 53 false )

y cuando veo por codigo fuente muestra lo siguiente:

Array
(
[0] => POST /Inventario.asmx HTTP/1.1
[1] => Host: 192.168.0.102:81
[2] => Content-Length: 477
[3] => Content-Type: text/xml; charset=utf-8
[4] => Connection: close
[5] => SOAPAction: "http://tempuri.org/GetTopSellersFromCategory"

[6] => <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetTopSellersFromCategory xmlns="http://tempuri.org/">
<ASIN>AMB000E43GP8</ASIN>
<NroArticulos>5</NroArticulos>
<CategoriaTraetelo>53</CategoriaTraetelo>
<UsarSemilla>false</UsarSemilla>
</GetTopSellersFromCategory>
</soap:Body>
</soap:Envelope>
)

en la posicion [6] del array falta la siguiente linea:

<?xml version="1.0" encoding="utf-8"?>

supongo que por esa razon no se podra parsear.

Muchas gracias de antemano!
  #2 (permalink)  
Antiguo 26/07/2010, 12:10
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: Php, Webservices - curl y soap

¿porque no usar una librería completa para SOAP?

NuSOAP
http://php.net/soap
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #3 (permalink)  
Antiguo 26/07/2010, 14:51
 
Fecha de Ingreso: julio-2010
Mensajes: 2
Antigüedad: 13 años, 9 meses
Puntos: 0
Respuesta: Php, Webservices - curl y soap

NUSOAP no me maneja el timeout con la conexion del webservice y eso queremos controlarlo, ya venimos de probar con una libreria completa de NUSOAP y funcionaba muy bien pero si el webservice se caía duraba como 1 min en mostrarnos el mensaje y es eso lo que queremos controlar

Gracias por responder

Etiquetas: curl, soap, webservice
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 06:41.