I am trying to consume a SOAP service, but one method is giving me the following error:
Server was unable to process request. ---> Object reference not set to an instance of an object.
I have done direct tests with a plugin for Chrome, and it returns the following XML:
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Header>
<AuthHeader xmlns="http://tempuri.org/">
<login>[string?]</login>
<pwd>[string?]</pwd>
<Id_CodFacturacion>[string?]</Id_CodFacturacion>
<Nombre_Cargue>[string?]</Nombre_Cargue>
</AuthHeader>
</Header>
<Body>
<GenerarGuiaSticker xmlns="http://tempuri.org/">
<num_Guia>[decimal]</num_Guia>
<num_GuiaFinal>[decimal]</num_GuiaFinal>
<ide_CodFacturacion>[string?]</ide_CodFacturacion>
<sFormatoImpresionGuia>[int]</sFormatoImpresionGuia>
<Id_ArchivoCargar>[string?]</Id_ArchivoCargar>
<interno>[boolean]</interno>
<bytesReport>[base64Binary?]</bytesReport>
</GenerarGuiaSticker>
</Body>
</Envelope>
The GenerateGuiaSticker method has an 'xmlns' parameter that coincidentally does not have other methods than this service used.
This is the code I use to consume this service:
<?php
$ns = "http://tempuri.org";
$headerBody = array(
'login' => 'xxxxxxx',
'pwd' => 'xxxxxxxxxxxxxxxxxxxx',
'Id_CodFacturacion' => 'xxxxxxxxxxxx',
'Nombre_Cargue' =>'xxxxxxxxxxx'
);
$header = new SOAPHeader($ns, 'AuthHeader', $headerBody);
$url = "http://web.servientrega.com:8081/GeneracionGuias.asmx?wsdl";
$client = new SoapClient($url, [ "trace" => 1 ] );
$client->__setSoapHeaders($header);
try {
$parametros = array(
'num_Guia' => xxxxxxxx,
'num_GuiaFinal' => xxxxxxxxx,
'ide_CodFacturacion' => 'xxxxxxx',
'sFormatoImpresionGuia' => 1,
'bytesReport'=> '',
'interno' => false
);
$result = $client->GenerarGuiaSticker($parametros, array('uri'=>$ns));
} catch ( SoapFault $e ) {
echo $e->getMessage();
}
?>
I have tried in many ways, using the SoapParam, SoapVar class, but nothing has worked, I have noticed that possibly the problem is that I am not correctly passing the name space for the method.
What would be the way to pass a parameter to a method when calling it, and / or pass a name space to a SOAP method with a PHP client?
Thank you.