SOAP请求在soapUI上工作,而不是在PHP上工作(simplexml_load_file也不能正常工作,名称空间的


SOAP request working on soapUI, not working on PHP (simplexml_load_file nor working right, problems with namespaces)

我快疯了,所以我写信给你,希望你能帮我。我正试图在PHP中请求SOAP服务器。

连接正常,就像这样:

$client = new SoapClient ($wsdl, array(
                                                'login' => $login, 
                                                'password' => $pass,
                                                'exceptions' => 1,
                                                "location" => "https://preregistroenvios.correos.es/preregistroenvios",
                                                "stream_context" => stream_context_create(
                                                        array(
                                                            'ssl' => array(
                                                                    'verify_peer'       => false,
                                                                    'verify_peer_name'  => false,
                                                                    )
                                                        )
                                                )));
            echo("No hay errores en la conexión<br /><br />");
        } catch (SoapFault $e) {
            echo("Hay errores en la conexión<br /><br />");
            print_r($client);
        }

上面没有错误。我想提出一个请求:ValidarDatosOp(它在wsdl中),我可以在SoapUI上实现它,它可以完美地工作。但我有问题与php,这是我在soapUI使用的xml文件:

   <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:prer="http://www.correos.es/">
   <soapenv:Header></soapenv:Header>
   <soapenv:Body>
      <prer:ValidarDatos>
         <!--You may enter the following 10 items in any order-->
         <prer:FechaOperacion>19</prer:FechaOperacion>
         <prer:CodEtiquetador></prer:CodEtiquetador>
         <!--Optional:-->
         <prer:NumContrato></prer:NumContrato>
         <!--Optional:-->
         <prer:NumCliente></prer:NumCliente>
         <prer:Care>000000</prer:Care>
         <!--Optional:-->
         <prer:TotalBultos>1</prer:TotalBultos>
         <prer:ModDevEtiqueta>2</prer:ModDevEtiqueta>
         <prer:Remitente>
            <!--You may enter the following 6 items in any order-->
            <prer:Identificacion>
               <!--You may enter the following 6 items in any order-->
               <!--Optional:-->
               <prer:Nombre>Oscar</prer:Nombre>
               <!--Optional:-->
               <prer:Apellido1>Gonzalez</prer:Apellido1>
               <!--Optional:-->
               <prer:Apellido2>Perez</prer:Apellido2>
               <!--Optional:-->
               <prer:Nif>11111111H</prer:Nif>
               <!--Optional:-->
               <prer:Empresa>´testtita</prer:Empresa>
               <!--Optional:-->
               <prer:PersonaContacto>Oscar</prer:PersonaContacto>
            </prer:Identificacion>
            <prer:DatosDireccion>
               <!--You may enter the following 10 items in any order-->
               <!--Optional:-->
               <prer:TipoDireccion></prer:TipoDireccion>
               <prer:Direccion>Calle Alpina</prer:Direccion>
               <!--Optional:-->
               <prer:Numero>10</prer:Numero>
               <!--Optional:-->
               <prer:Portal></prer:Portal>
               <!--Optional:-->
               <prer:Bloque></prer:Bloque>
               <!--Optional:-->
               <prer:Escalera></prer:Escalera>
               <!--Optional:-->
               <prer:Piso>1</prer:Piso>
               <!--Optional:-->
               <prer:Puerta></prer:Puerta>
               <prer:Localidad>Salamanca</prer:Localidad>
               <!--Optional:-->
               <prer:Provincia>Salamanca</prer:Provincia>
            </prer:DatosDireccion>
            <prer:CP>37184</prer:CP>
            <!--Optional:-->
            <prer:Telefonocontacto></prer:Telefonocontacto>
            <!--Optional:-->
            <prer:Email></prer:Email>
            <!--Optional:-->
            <prer:DatosSMS>
               <!--You may enter the following 2 items in any order-->
               <!--Optional:-->
               <prer:NumeroSMS></prer:NumeroSMS>
               <!--Optional:-->
               <prer:Idioma>1</prer:Idioma>
            </prer:DatosSMS>
         </prer:Remitente>
         <prer:Destinatario>
            <!--You may enter the following 11 items in any order-->
            <prer:Identificacion>
               <!--You may enter the following 6 items in any order-->
               <!--Optional:-->
               <prer:Nombre>Sofia</prer:Nombre>
               <!--Optional:-->
               <prer:Apellido1>Cid</prer:Apellido1>
               <!--Optional:-->
               <prer:Apellido2>Gonzalez</prer:Apellido2>
               <!--Optional:-->
               <prer:Nif>11111111H</prer:Nif>
               <!--Optional:-->
               <prer:Empresa>kkfuti</prer:Empresa>
               <!--Optional:-->
               <prer:PersonaContacto>patata</prer:PersonaContacto>
            </prer:Identificacion>
            <prer:DatosDireccion>
               <!--You may enter the following 10 items in any order-->
               <!--Optional:-->
               <prer:TipoDireccion></prer:TipoDireccion>
               <prer:Direccion>Calle Rosales</prer:Direccion>
               <!--Optional:-->
               <prer:Numero>13</prer:Numero>
               <!--Optional:-->
               <prer:Portal></prer:Portal>
               <!--Optional:-->
               <prer:Bloque></prer:Bloque>
               <!--Optional:-->
               <prer:Escalera></prer:Escalera>
               <!--Optional:-->
               <prer:Piso>1</prer:Piso>
               <!--Optional:-->
               <prer:Puerta>F</prer:Puerta>
               <prer:Localidad>Villares de la Reina</prer:Localidad>
               <!--Optional:-->
               <prer:Provincia>Salamanca</prer:Provincia>
            </prer:DatosDireccion>
            <prer:DatosDireccion2>
               <!--You may enter the following 10 items in any order-->
               <!--Optional:-->
               <prer:TipoDireccion></prer:TipoDireccion>
               <prer:Direccion>Calle Rosales</prer:Direccion>
               <!--Optional:-->
               <prer:Numero>13</prer:Numero>
               <!--Optional:-->
               <prer:Portal></prer:Portal>
               <!--Optional:-->
               <prer:Bloque></prer:Bloque>
               <!--Optional:-->
               <prer:Escalera></prer:Escalera>
               <!--Optional:-->
               <prer:Piso>1</prer:Piso>
               <!--Optional:-->
               <prer:Puerta>F</prer:Puerta>
               <prer:Localidad>Salamanca</prer:Localidad>
               <!--Optional:-->
               <prer:Provincia>Salamanca</prer:Provincia>
            </prer:DatosDireccion2>
            <!--Optional:-->
            <prer:CP>37184</prer:CP>
            <!--Optional:-->
            <prer:ZIP></prer:ZIP>
            <!--Optional:-->
            <prer:Pais></prer:Pais>
            <!--Optional:-->
            <prer:DestinoApartadoPostalinternacional></prer:DestinoApartadoPostalinternacional>
            <!--Optional:-->
            <prer:ApartadoPostaldestino></prer:ApartadoPostaldestino>
            <!--Optional:-->
            <prer:Telefonocontacto>652942695</prer:Telefonocontacto>
            <!--Optional:-->
            <prer:Email></prer:Email>
            <!--Optional:-->
            <prer:DatosSMS>
               <!--You may enter the following 2 items in any order-->
               <!--Optional:-->
               <prer:NumeroSMS></prer:NumeroSMS>
               <!--Optional:-->
               <prer:Idioma>1</prer:Idioma>
            </prer:DatosSMS>
         </prer:Destinatario>
         <prer:Envio>
            <!--You may enter the following 48 items in any order-->
            <!--Optional:-->
            <prer:NumBulto>01</prer:NumBulto>
            <prer:CodProducto>S0030</prer:CodProducto>
            <!--Optional:-->
            <prer:ReferenciaCliente></prer:ReferenciaCliente>
            <!--Optional:-->
            <prer:ReferenciaCliente2></prer:ReferenciaCliente2>
            <!--Optional:-->
            <prer:ReferenciaCliente3></prer:ReferenciaCliente3>
            <!--Optional:-->
            <prer:TipoFranqueo>FP</prer:TipoFranqueo>
            <!--Optional:-->
            <prer:NumMaquinaFranquear></prer:NumMaquinaFranquear>
            <!--Optional:-->
            <prer:ImporteFranqueado></prer:ImporteFranqueado>
            <!--Optional:-->
            <prer:CodPromocion></prer:CodPromocion>
            <!--Optional:-->
            <prer:ModalidadEntrega>ST</prer:ModalidadEntrega>
            <!--Optional:-->
            <prer:OficinaElegida></prer:OficinaElegida>
            <prer:Pesos>
               <!--1 to 2 repetitions:-->
               <prer:Peso>
                  <!--You may enter the following 2 items in any order-->
                  <prer:TipoPeso>R</prer:TipoPeso>
                  <prer:Valor>300</prer:Valor>
               </prer:Peso>
            <prer:Peso>
                  <!--You may enter the following 2 items in any order-->
                  <prer:TipoPeso>V</prer:TipoPeso>
                  <prer:Valor>450</prer:Valor>
               </prer:Peso>
            </prer:Pesos>
            <!--Optional:-->
            <prer:Largo>50</prer:Largo>
            <!--Optional:-->
            <prer:Alto>50</prer:Alto>
            <!--Optional:-->
            <prer:Ancho>50</prer:Ancho>
            <!--Optional:-->
            <prer:ValoresAnadidos>
               <!--You may enter the following 14 items in any order-->
               <!--Optional:-->
               <prer:ImporteSeguro></prer:ImporteSeguro>
               <!--Optional:-->
               <prer:Reembolso>
                  <!--You may enter the following 4 items in any order-->
                  <prer:TipoReembolso>RC</prer:TipoReembolso>
                  <prer:Importe>90050</prer:Importe>
                  <!--Optional:-->
                  <prer:NumeroCuenta>0123456789012345</prer:NumeroCuenta>
                  <!--Optional:-->
                  <prer:Transferagrupada>S</prer:Transferagrupada>
               </prer:Reembolso>
               <!--Optional:-->
               <prer:EntregaExclusivaDestinatario></prer:EntregaExclusivaDestinatario>
               <!--Optional:-->
               <prer:PruebaEntrega>
                  <!--You may enter the following 3 items in any order-->
                  <!--Optional:-->
                  <prer:Formato>0</prer:Formato>
                  <!--Optional:-->
                  <prer:ReferenciaeAR></prer:ReferenciaeAR>
                  <!--Optional:-->
                  <prer:InfRemitenteEAr></prer:InfRemitenteEAr>
               </prer:PruebaEntrega>
               <!--Optional:-->
               <prer:Recogidaadomicilio></prer:Recogidaadomicilio>
               <!--Optional:-->
               <prer:DevolucionAlbaran></prer:DevolucionAlbaran>
               <!--Optional:-->
               <prer:RepartoenSabado></prer:RepartoenSabado>
               <!--Optional:-->
               <prer:EntregaConcertada></prer:EntregaConcertada>
               <!--Optional:-->
               <prer:FranjaHorariaConcertada></prer:FranjaHorariaConcertada>
               <!--Optional:-->
               <prer:EntregaconRecogida></prer:EntregaconRecogida>
               <!--Optional:-->
               <prer:IndImprimirEtiqueta></prer:IndImprimirEtiqueta>
               <!--Optional:-->
               <prer:TextoAdicional></prer:TextoAdicional>
               <!--Optional:-->
               <prer:TiempoEnLista>1</prer:TiempoEnLista>
               <!--Optional:-->
               <prer:IntentosDeEntrega>1</prer:IntentosDeEntrega>
            </prer:ValoresAnadidos>
            <!--Optional:-->
            <prer:CodigoEmbalajePrepago></prer:CodigoEmbalajePrepago>
            <!--Optional:-->
            <prer:CodigoPuntoAdmision></prer:CodigoPuntoAdmision>
            <!--Optional:-->
            <prer:FechaDepositoPrevista></prer:FechaDepositoPrevista>
            <!--Optional:-->
            <prer:Observaciones1></prer:Observaciones1>
            <!--Optional:-->
            <prer:Observaciones2></prer:Observaciones2>
            <!--Optional:-->
            <prer:InstruccionesDevolucion>D</prer:InstruccionesDevolucion>
            <!--Optional:-->
            <prer:Aduana>
               <!--You may enter the following 8 items in any order-->
               <prer:TipoEnvio>2</prer:TipoEnvio>
               <!--Optional:-->
               <prer:EnvioComercial></prer:EnvioComercial>
               <!--Optional:-->
               <prer:FacturaSuperiora500></prer:FacturaSuperiora500>
               <!--Optional:-->
               <prer:DUAConCorreos></prer:DUAConCorreos>
               <!--Optional:-->
               <prer:DescAduanera>
                  <!--1 to 3 repetitions:-->
                  <prer:DATOSADUANA>
                     <!--You may enter the following 6 items in any order-->
                     <!--Optional:-->
                     <prer:Cantidad>1</prer:Cantidad>
                     <!--Optional:-->
                     <prer:Descripcion></prer:Descripcion>
                     <!--Optional:-->
                     <prer:Pesoneto>300</prer:Pesoneto>
                     <!--Optional:-->
                     <prer:Valorneto></prer:Valorneto>
                     <!--Optional:-->
                     <prer:NTarifario></prer:NTarifario>
                     <!--Optional:-->
                     <prer:PaisOrigen></prer:PaisOrigen>
                  </prer:DATOSADUANA>
               </prer:DescAduanera>
               <!--Optional:-->
               <prer:Factura></prer:Factura>
               <!--Optional:-->
               <prer:Licencia></prer:Licencia>
               <!--Optional:-->
               <prer:Certificado></prer:Certificado>
            </prer:Aduana>
            <!--Optional:-->
            <prer:CodigoIda></prer:CodigoIda>
            <!--Optional:-->
            <prer:PermiteEmbalaje></prer:PermiteEmbalaje>
            <!--Optional:-->
            <prer:FechaCaducidad></prer:FechaCaducidad>
            <!--Optional:-->
            <prer:ReferenciaExpedicion></prer:ReferenciaExpedicion>
            <!--Optional:-->
            <prer:CodigoHomepaq></prer:CodigoHomepaq>
            <!--Optional:-->
            <prer:ToquenIdCorPaq></prer:ToquenIdCorPaq>
            <!--Optional:-->
            <!--<prer:AdmisionHomepaq></prer:AdmisionHomepaq>-->
            <!--Optional:-->
            <prer:Documento1></prer:Documento1>
            <!--Optional:-->
            <prer:AccDocumento1></prer:AccDocumento1>
            <!--Optional:-->
            <prer:ObsDocumento1></prer:ObsDocumento1>
            <!--Optional:-->
            <prer:Documento2></prer:Documento2>
            <!--Optional:-->
            <prer:AccDocumento2></prer:AccDocumento2>
            <!--Optional:-->
            <prer:ObsDocumento2></prer:ObsDocumento2>
            <!--Optional:-->
            <prer:Documento3></prer:Documento3>
            <!--Optional:-->
            <prer:AccDocumento3></prer:AccDocumento3>
            <!--Optional:-->
            <prer:ObsDocumento3></prer:ObsDocumento3>
            <!--Optional:-->
            <prer:OperadorPostal></prer:OperadorPostal>
            <!--Optional:-->
            <prer:CodigoEnvioOriginal></prer:CodigoEnvioOriginal>
            <!--Optional:-->
            <prer:ExisteEnvioVueltaLI></prer:ExisteEnvioVueltaLI>
            <!--Optional:-->
            <prer:SeguroLI></prer:SeguroLI>
            <!--Optional:-->
            <prer:ImporteSeguroLI></prer:ImporteSeguroLI>
            <!--Optional:-->
            <prer:ReembolsoLI></prer:ReembolsoLI>
            <!--Optional:-->
            <prer:ImporteReembolsoLI></prer:ImporteReembolsoLI>
            <!--Optional:-->
            <prer:TipoReembolsoLI></prer:TipoReembolsoLI>
            <!--Optional:-->
            <prer:NumeroCuentaLI></prer:NumeroCuentaLI>
         </prer:Envio>
      </prer:ValidarDatos>
   </soapenv:Body>
</soapenv:Envelope>

对于在php中使用它,我尝试了以下代码:

$xml = simplexml_load_file("files/ValidarDatos.xml", null, null, 'soapenv', true);
        try {
            $result = $client->ValidarDatosOp($xml);
        } catch(SoapFault $e) {
            echo ("There are some errors on Validar datos<br />");
            print_r($client);
        }

但是它不工作(SOAP-ERROR: Encoding: object没有' identity '属性)。这是没有意义的,因为它是在SOAPUI上工作的,并且有一个"标识"属性。我检查了$xml变量,它是空的。

如果我创建一个print_r()来显示它,我得到这个:

SimpleXMLElement Object ( [Header] => SimpleXMLElement Object ( ) [Body] => SimpleXMLElement Object ( ) )

它是空的!我想是因为信封和前缀。我已经尝试了很多方法来解决它,但我没有找到一个解决方案。

第一次尝试尝试以其他方式读取xml。我尝试了一些选项(没有成功)

$xml->children('http://schemas.xmlsoap.org/soap/envelope/')->Body 

另一个尝试:

$xml->registerXPathNamespace("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
print_r($xml->xpath('//soapenv:Body'));

第二次尝试我还尝试更改xml以使其更简单。我试图删除信封和前缀,但随后我从SOAP服务器得到一个错误,所以它似乎是强制性的。

虽然,重要的是,如果我删除信封和前缀,我没有问题,读取xml文件,我只是得到一个异常从服务器(因为没有信封)。

任何想法?

即使这是将近2年的时间,如果有人再次尝试,最好找curl: http://php.net/manual/es/book.curl.php