Re: Consumiendo un servicio web asmx con php
| From: | SkuNk | Date: | Fri, 28 Dec 2007 23:38:59 +0000 |
| Subject: | Re: Consumiendo un servicio web asmx con php | ||
| References: | 1 2 3 4 5 | Groups: | php.general.es |
| Request: | Send a blank email to general-es+get-62008@lists.php.net to get a copy of this message | ||
El día 29/12/07, David Bautista Naveros <mipisha@hotmail.com> escribió:
>
> Gracias Philip :-)
>
> Pues consigo conectar con el servicio web pero me da un error y no me
> devuelve resultados. Te pongo el código con el que hago la solicitud y
> también el resultado que me muestra por si vieras algo que yo soy incapaz de
> ver:
>
> SOLICITUD CON PHP:
>
> <? require_once('lib/nusoap.php'); // define the soapaction as
> found in the wsdl $soapaction = "
> http://localhost/WebSite1/devuelveStock"; //
> endpoint address $wsdl
> = "http://localhost/WebSite1/Service.asmx?WSDL";
> $namespace = "
> http://localhost/WebSite1/"; $client = new
> soapclient($wsdl); $mysoapmsg
> = $client->serializeEnvelope('<devuelveStock xmlns="
> http://localhost/WebSite1/">
> <codigo>258</codigo>
> </devuelveStock>','',array(),'document',
> 'literal');
> /* Send the SOAP message and specify the soapaction */
> $response = $client->send($mysoapmsg, $soapaction);
> if ($client->fault) { echo
> '<h3>Fault</h3><pre>'; print_r($response); echo
> '</pre>'; }
> echo "<p>SOAP query</p>"; echo '<pre>' .
> htmlspecialchars($client->request, ENT_QUOTES) . '</pre>'; echo
> "<p>SOAP
> response</p>"; echo '<pre>' . htmlspecialchars($client->response,
> ENT_QUOTES) . '</pre>';
> // start to use the result by following the structure of the SOAP
> response // first extract the SearchResult $searchresult =
> $response["devuelveStockResponse"]; // then you can access the Status
> message echo "Status message: ".$searchresult["Status"]; // continue
> with the Result level $result = $searchresult["Result"]; // wich
> allow access to NumRecs (number of record found) echo "<br>Record found:
> ".$result["NumRecs"]; // extract the collection of record (object
> collRecord) $collrecord = $result["collRecord"]; foreach
> ($collrecord["CRecord"] as $record){ echo "<br>Name:
> ".$record["Name"]; echo "<br>Address:
> ".$record["Address"]; //...... and so on..... }?>
>
> RESULTADO QUE ME DEVUELVE EL CÓDIGO ANTERIOR:
>
> Notice: Undefined property: soapclient::$operation in
> c:\Inetpub\wwwroot\web\lib\nusoap.php on line 7519
> SOAP queryPOST /WebSite1/Service.asmx?WSDL HTTP/1.0
> Host: localhost
> User-Agent: NuSOAP/0.7.3 (1.114)
> Content-Type: text/xml; charset=ISO-8859-1
> SOAPAction: "http://localhost/WebSite1/devuelveStock"
> Content-Length: 497
>
> <?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/"!sžHȝ
> ÆÜd 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><devuelveStock
> xmlns="http://localhost/WebSite1/">
> <codigo>258</codigo>
> </devuelveStock></SOAP-ENV:Body></SOAP-ENV:Envelope>
> SOAP responseHTTP/1.1 500 Internal Server Error
> Server: Microsoft-IIS/5.1
> Date: Fri, 28 Dec 2007 22:47:24 GMT
> X-Powered-By: ASP.NET
> X-AspNet-Version: 2.0.50727
> Cache-Control: private
> Content-Type: text/xml; charset=utf-8
> Content-Length: 910
>
> <?xml version="1.0" encoding="utf-8"?><soap:Envelope
> xmlns:soap="
> http://schemas.xmlsoap.org/soap/envelope/"
> xmlns:xsi="
> http://www.w3.org/2001/XMLSchema-instance"
> xmlns:xsd="
> http://www.w3.org/2001/XMLSchema
>
> "><soap:Body><soap:Fault><faultcode>soap:Client</faultcode><faultstring>
> System.Web.Services.Protocols.SoapException: El servidor no reconoció el
> valor del encabezado HTTP SOAPAction:
> http://localhost/WebSite1/devuelveStock.
> en
> System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest()
> en System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage
> message)
> en System.Web.Services.Protocols.SoapServerProtocol.Initialize()
> en System.Web.Services.Protocols.ServerProtocolFactory.Create(Type
> type, HttpContext context, HttpRequest request, HttpResponse response,
> Boolean& abortProcessing)</faultstring><detail
> /></soap:Fault></soap:Body></soap:Envelope>
> Notice: Undefined index: devuelveStockResponse in
> c:\Inetpub\wwwroot\web\servicio2.php on line 33Status message: Record found:
> Warning: Invalid argument supplied for foreach() in
> c:\Inetpub\wwwroot\web\servicio2.php on line 43
>
> David Bautista Naveros
>
>
Estás atacando a un WSDL local, es decir, en tu propia máquina. ¿Tienes un
Servicio Web instalado en tu equipo?
Aparte de eso, lo primero que deberías comprobar es esa línea de error que
te devuelve el script, y asegurarte de que estás utilizando la última
versión de NuSOAP, o que no se haya podido alterar.
--
Atentamente,
Philipp Keweloh