SOAP XML - Object reference not set to an instance of an object

Hi, this is my first time using this forum.

I´m trying to send and recieve XML data using curl.
The response is written to a file on the server. But I only get this response:


<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>Server was unable to process request. ---> Object reference not set to an instance of an object.</faultstring>
<detail />
</soap:Fault>

Here is my code:


echo 'POST /checkout_process.php HTTP/1.1
Host: www.xxxx.se
Content-Type: application/soap+xml; charset=ISO-8859-1
SOAPAction: "http://www.xxxxx.se/Services/CreditTemplate/CreditTemplatePerson"';

$data='<?xml version="1.0" encoding="ISO-8859-1"?>
<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:Body>
    <CreditTemplatePerson xmlns="http://www.xxxxx.se/Services/CreditTemplate">
      <CustomerLoginName>'.$CustomerLoginName.'</CustomerLoginName>
      <UserLoginName>'.$UserLoginName.'</UserLoginName>
      <Password>'.$Password.'</Password>
      <Language>'.$Language.'</Language>
      <TemplateName>'.$TemplateName.'</TemplateName>
      <PersonNumber>'.$PersonNumber.'</PersonNumber>
      <FirstName>'.$FirstName.'</FirstName>
      <LastName>'.$LastName.'</LastName>
      <Address>'.$Address.'</Address>
      <ZipCode>'.$ZipCode.'</ZipCode>
      <City>'.$City.'</City>
	  <CustomerPopularName>'.$CustomerPopularName.'</CustomerPopularName>
	  <OmfragadEmail>'.$OmfragadEmail.'</OmfragadEmail>
    </CreditTemplatePerson>
  </soap:Body>
</soap:Envelope>';


 $f_name="XML/ADDRESS/".$customer_id.'.xml';
	if (file_exists($f_name)) {
    unlink($f_name);
	}

	$file=fopen($f_name,"w+") or exit("Unable to open file!");
 	fwrite($file,$data);
	fclose($file);
	chmod($f_name,0777);
	
	
	  $ch = curl_init();
	  curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml;charset=ISO-8859-1"));
	  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
	  curl_setopt($ch, CURLOPT_URL, $soap_url);
	  curl_setopt($ch, CURLOPT_USERPWD, "$UserLoginName:$Password");
	  //curl_setopt ($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
	  curl_setopt($ch, CURLOPT_POST, 1);
	  curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
	  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	
	  $response = curl_exec($ch);
	  curl_close($ch);
	
 $fp = fopen("XML/ADDRESS/".$customer_id."_response.xml", "w+");
   fwrite($fp,$response);

Can you see what I am doing wrong?
Any help would be gratefully appreciated.

Sounds like the soap server is expecting an object and getting something else. I’d check the soap server’s documentation. I don’t see any classes in your code, so it doesn’t look like there is an object to pass in the xml.

Thanks for your reply!

However, it seems that the problem was due to a simple mistake on my part.
I forgot to include empty strings for the fields I don´t need to use :rolleyes:.

Again, thanks for your time!