Passing values to header and body of SOAP

Hi there,
I’m very happy to join this community for the first time. I some good knowledge of php but I’m really new the PHP SOAP. I have a webservice document that has the SOAP structure to pass values to the function and get the response. This is the structure:

				POST /WSAutorizaciones/WSAutorizacionLaboratorio.asmx HTTP/1.1
			Host: 191.97.91.43
			Content-Type: text/xml; charset=utf-8
			Content-Length: length
			SOAPAction: "https://arsvesa.como/ConsultarAfiliado"

			<?xml version="1.0" encoding="utf-8"?>
			<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
			<soap:Header>
			<AuthenticationHeader xmlns="https://arsvesa.com/">
			<Cedula>string</Cedula>
			<Password>string</Password>
			<Proveedo>int</Proveedo>
			</AuthenticationHeader>
			</soap:Header>
			<soap:Body>
			<ConsultarAfiliado xmlns="https://arssenasa.gob.do/">
			<TipoDocumento>int</TipoDocumento>
			<NumDocumento>string</NumDocumento>
			</ConsultarAfiliado>
			</soap:Body>
			</soap:Envelope>

I try to consume the function *ConsultarAfiliado * like this:
$wsdl = “http://189.27.91.43/WSAutorizaciones/WSAutorizacionLaboratorio.asmx?WSDL”;
$client = new SoapClient($wsdl, array(‘trace’ => 1)); // The trace param will show you errors stack

			$auth =array('Cedula' => '02109427015', 'Password' => 'dmfvmxm2', 'Proveedo' => '12077');
			$header = new SoapHeader('NAMESPACE','AuthenticationHeader',$auth,false);
			var_dump($client->__setSoapHeaders($header));

			// web service input params
			$request_param = array('TipoDocumento' => '2', 'NumDocumento' => '021827151');
			$responce_param = null;
			try {
			$responce_param = $client->ConsultarAfiliado($request_param);

			print_r($responce_param->ConsultarAfiliadoResponse);
			} catch (Exception $e) {
			echo "<h2>Exception Error!</h2>";
			echo $e->getMessage();
			}

I got his error: *I got this error:

Exception Error! Server was unable to process request. —> Object reference not set to an instance of an object.*
As I’m new to using SOAP would anyone help me to solve that out.

Many thanks

hello, I did not withdrawn my post, why you mention that ?

COLT deleted HIS post…

Is the end point even set-up? Whats at this IP: [http://189.27.91.43] if you go there directly in the browser? Anything?

the correct end point is: http://191.97.91.43/WSAutorizaciones/WSAutorizacionConsulta.asmx?WSDL

yes I got the wsl file in the browser, I even consumed in postman.

Hi @baptiste.prophete I recorded this video about auth with PHP Soap using headers some time ago. I believe it can come in handy for you :wink:

1 Like

Many thanks guy, you save my live. I did it thanks to you…

1 Like

Great! Glad to help.

Share the video around :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service