Foros del Web » Programando para Internet » PHP »

Consumir webservice XML

Estas en el tema de Consumir webservice XML en el foro de PHP en Foros del Web. Buenas tardes Desarrolle un formulario para registro de participantes en una encuesta en php y mysql, pero me estan pidiendo que ahora envie los datos ...
  #1 (permalink)  
Antiguo 12/09/2011, 13:35
 
Fecha de Ingreso: noviembre-2009
Mensajes: 16
Antigüedad: 14 años, 5 meses
Puntos: 0
Consumir webservice XML

Buenas tardes

Desarrolle un formulario para registro de participantes en una encuesta en php y mysql, pero me estan pidiendo que ahora envie los datos a otro servidor utilizando un webservice. Para ello me enviaron los siguiente:

Código:
Webservice URL:	http://www.ezpzapp.com/html/sweepstakes.cfc?wsdl

Webservice Method:	SubmitForm

Sample SOAP Request
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope 
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">    
    <soapenv:Body>
        <SubmitForm xmlns="http://ezpzapp.com/sweepstakes"">
            <FormID>28</FormID>
            <language>1</language>
            
            <formfield>
                <name>First Name</name>
                <value>user entered value here</value>
            </formfield>
            <formfield>
                <name>Last Name</name>
                <value>user entered value here</value>
            </formfield>
            <formfield>
                <name>Email</name>
                <value>user entered value here</value>
            </formfield>
            <formfield>
                <name>Birth Date</name>
                <value>user entered value here</value>
            </formfield>
            <formfield>
                <name>City</name>
               <value>user entered value here</value>
            </formfield>
            <formfield>
                <name>Country</name>
                <value>user entered value here</value>
            </formfield>
        </SubmitForm>
    </soapenv:Body>
</soapenv:Envelope>
Pero no tengo ni idea de como utilizarlo en el formulario que construi. Si alquien puede ayudarme se los agradecería.
  #2 (permalink)  
Antiguo 12/09/2011, 13:49
Avatar de abimaelrc
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 14 años, 10 meses
Puntos: 1517
Respuesta: Consumir webservice XML

Para enviar eso puedes usar cURL y enviarlo como una petición, ejemplo de uso
Código PHP:
Ver original
  1. <?php
  2. $xml = '<?xml version="1.0" encoding="utf-8"?>
  3. <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  4.    <soapenv:Body>
  5.        <SubmitForm xmlns="http://ezpzapp.com/sweepstakes">
  6.            <FormID>28</FormID>
  7.            <language>1</language>
  8.            
  9.            <formfield>
  10.                <name>First Name</name>
  11.                <value>user entered value here</value>
  12.            </formfield>
  13.            <formfield>
  14.                <name>Last Name</name>
  15.                <value>user entered value here</value>
  16.            </formfield>
  17.            <formfield>
  18.                <name>Email</name>
  19.                <value>user entered value here</value>
  20.            </formfield>
  21.            <formfield>
  22.                <name>Birth Date</name>
  23.                <value>user entered value here</value>
  24.            </formfield>
  25.            <formfield>
  26.                <name>City</name>
  27.               <value>user entered value here</value>
  28.            </formfield>
  29.            <formfield>
  30.                <name>Country</name>
  31.                <value>user entered value here</value>
  32.            </formfield>
  33.        </SubmitForm>
  34.    </soapenv:Body>
  35. </soapenv:Envelope>';
  36. $url = 'http://www.ezpzapp.com/html/sweepstakes.cfc?wsdl';
  37. $header = array();
  38. $header[] = 'Content-Type: text/xml;charset=UTF-8';
  39. $header[] = 'SOAPAction: ""';
  40. $header[] = 'Accept-Encoding: gzip,deflate';
  41.  
  42. $ch = curl_init();
  43. curl_setopt($ch, CURLOPT_URL, $url); // set url to post to
  44. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // allow redirects
  45. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable
  46. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  47. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  48. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  49. curl_setopt($ch, CURLOPT_POST, 1);
  50. curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
  51. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  52. curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
  53. $data = curl_exec($ch);
  54. echo $data;
En internet hay mucho material que te puede ayudar con lo que quieres hacer, te recomiendo que hagas una búsqueda para que así te puedas desenvolver.
__________________
Verifica antes de preguntar.
Los verdaderos amigos se hieren con la verdad, para no perderlos con la mentira. - Eugenio Maria de Hostos

Última edición por abimaelrc; 12/09/2011 a las 13:57 Razón: corregir un error en el código
  #3 (permalink)  
Antiguo 12/09/2011, 14:10
 
Fecha de Ingreso: noviembre-2009
Mensajes: 16
Antigüedad: 14 años, 5 meses
Puntos: 0
Respuesta: Consumir webservice XML

Gracias, seguire en la investigación tomando en cuenta la información que me distes.

Etiquetas: xml
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 15:06.