Ver Mensaje Individual
  #1 (permalink)  
Antiguo 26/10/2015, 15:17
felipebravotapia
 
Fecha de Ingreso: octubre-2015
Ubicación: Santiago
Mensajes: 3
Antigüedad: 8 años, 6 meses
Puntos: 0
Consumir Web Service Soap con PHP

Buenas.., amigos del foro. necesito su ayuda.!
un proveedor de gps nos dispuso un WS para ser consumido a través de nuestro hosting.
lo unico que he podido hacer es consumir el WS con un ajax que me encontre en la web al cual lo adapte y logre rescatar algunos datos. La problematica que tengo es que tengo algunos problemas de Access-control-Expose-Headers

adjunto mi codigo, la verdad necesito si alguien me puede ayudar a consumir este WS solo con PHP y alguna libreria facil de entender.
saludos!

Código PHP:
Ver original
  1. <?php
  2. include "../config.php";
  3. ?>
  4.  
  5.  
  6. <html xmlns="http://www.w3.org/1999/xhtml">
  7.  <head>
  8.     <title>Calling Web Service from jQuery</title>
  9.    
  10.    
  11.      <style>
  12.       html, body {
  13.         height: 100%;
  14.         margin: 0;
  15.         padding: 0;
  16.       }
  17.       #map {
  18.         height: 100%;
  19.       }
  20.     </style>
  21.  
  22.     <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
  23.     <script src="https://maps.googleapis.com/maps/api/js?signed_in=true"></script>
  24.    
  25.     <?php
  26.   $variablephp = "PHJlcXVlc3Q+PGxvZ2luPmFzZXNvcmlhczwvbG9naW4+DQo8cGFzc3dvcmQ+NDE2c2VydmljaW9zPC9wYXNzd29yZD4NCjxwaHlzaWQ+MzU3NjY2MDUxMzM3NTE0PC9waHlzaWQ+PC9yZXF1ZXN0Pg==";
  27.     ?>
  28.  
  29.     <script type="text/javascript">
  30.    
  31.    
  32.     var variablejs = "<?php echo $variablephp; ?>" ;
  33.    
  34.    
  35.         $(document).ready(function () {
  36.                      
  37.                 var wsUrl = "http://416.fleetport.net/Monitoreo.asmx";
  38.  
  39.                 var l1 = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/"><soapenv:Header/><soapenv:Body><tem:getLastPositionById><tem:request>' + variablejs +'</tem:request></tem:getLastPositionById></soapenv:Body></soapenv:Envelope>';
  40.                
  41.  
  42.                 var soapRequest =l1  ;
  43.  
  44.                $.ajax({
  45.   type: "POST",                    
  46.   url: wsUrl,
  47.   contentType: "text/xml",
  48.   dataType: "xml",
  49.   crossDomain: true,
  50.   data: soapRequest,
  51.   success: processSuccess,
  52.   error: processError
  53. });
  54.         });
  55.        
  56.        function processSuccess(data, status, req) {
  57.             if (status == "success")
  58.            // $("#response").text($(req.responseXML).find("getLastPositionByIdResult").text());
  59.  
  60.             var value = ($(req.responseXML).find("patente").text());
  61.            
  62.                 $("#patente").val(value);
  63.                 $("#patente2").val(value);
  64.  
  65.            lat = ($(req.responseXML).find("latitud").text());
  66.            
  67.                 $("#latitud").val(lat);
  68.  
  69.            lng = ($(req.responseXML).find("longitud").text());
  70.            
  71.                 $("#longitud").val(lng);
  72.                
  73.             var value = ($(req.responseXML).find("serieGSM").text());
  74.            
  75.             $("#imei").val(value);
  76.            
  77.            
  78.             var value = ($(req.responseXML).find("calle").text());
  79.            
  80.             $("#calle2").val(value);
  81.                
  82.                
  83.                 var value = ($(req.responseXML).find("velocidad").text());
  84.            
  85.             $("#velocidad").val(value);
  86.    
  87.             var value = ($(req.responseXML).find("fechaHoraSistema").text());
  88.            
  89.             $("#fecha").val(value);
  90.  
  91.         }
  92.  
  93.   function processError(data, status, req) {
  94.             alert(req.responseText + " " + status);
  95.         }
  96.  
  97.     </script>
  98.  
  99. </head>
  100. <body>
  101.  
  102.     <input id="btnCallWebService" value="Call web service" type="button" />
  103.    
  104.  <form method="post" action="../registro_GPS.php">
  105. <input type="text" id="patente" name="patente" value=""/>
  106. <br>
  107. <input type="text" id="latitud" name="latitud"value=""/>
  108. <br>
  109. <input type="text" id="longitud" name="longitud" value=""/>
  110. <br>
  111. <input type="text" id="velocidad" name="velocidad"value=""/>
  112. <br>
  113. <input type="text" id="calle2" name="calle2" value=""/>
  114. <br>
  115. <input type="text" id="imei" name="imei"value=""/>
  116. <br>
  117. <input type="text" id="fecha"name="fecha" value=""/>
  118. <button type="submit" class="btn btn-primary">Enviar</button>
  119. </form>
  120.  
  121.   <form id="form1" method="post" action="gpsUNO.php" role="form">
  122.     <input type="text" id="patente2" name="patente2" value=""/>
  123. <button type="submit" class="btn btn-primary">Ver MAPA</button>
  124.     </form>
  125.  
  126.        
  127.                  <?php
  128.                 $patente = $_POST['patente2'];               
  129.                  echo  $patente;                               
  130.                     $db = new MySQL();
  131.                     $consulta = $db->consulta("select * from GPS where patente = '$patente'" );                                    
  132.  
  133.                     if($db->num_rows($consulta)>0){
  134.                     while($resultados3 = $db->fetch_array($consulta)){
  135.                             ?>     
  136.                                 <center>
  137.                          <iframe
  138.                     width="90%"
  139.                     height="400px"
  140.                     frameborder="0" style="border:0"
  141.                     src="https://www.google.com/maps/embed/v1/directions?key=AIzaSyBl7XAviMyBkMHVHh54ab3lePOiqJr596c
  142.                     &origin=<?php echo $resultados3['latitud']?>,<?php echo $resultados3['longitud']?>
  143.                     &destination=<?php echo $resultados2['comuna']?>,<?php echo $resultados2['calle']?>,<?php echo $resultados2['numero']?>, chile         
  144.                     " >
  145.                         </iframe>      
  146.                                 </center>                  
  147.                           <?php
  148.                         }
  149.                     }
  150.                     ?> 
  151.                  
  152.    
  153.    
  154. </body>
  155. </html>