Jump to content

How do I use SOAP to transmit an XML?


Dakkadakka

Recommended Posts

I am trying to make a shopping cart and am using a web service my partner made to complete a transaction. The idea is to build an xml sheet and then transmit it to the web service using SOAP, but since PHP is a web language I am having problems. The web service is expecting a string, but the web service keeps getting a null pointer each time I try to submit the XML.

$xmlDocument = '<?xml version="1.0" encoding="utf-16"?>';  $xmlDocument.= '<SalesOrder dateCreated="'.$year.'-'.$mon.'-'.$day.' '.$hour.':'.$minutes.':'.$seconds.'" amount="'.$amount.'" mark_up="15.0000" customerID="'.$customer_id.'" employeeID="80000003-1325611163" source="0">'; while($row=mysql_fetch_array($result)){   //Product Id is called ProductID in the XML$product_id = $row['product_id'];  //Sales info is NOT needed for the order.$sales_info = $row['sales_info'];echo $sales_info.'<br>';//Final price is called SalesPrice in the XML$final_price = $row['final_price'];echo $final_price.'<br>';//qty is called Quantity in the XML$qty = $row['qty'];echo $qty.'<br>';//Purchase cost is called PurchaseCost in the XML$purchase_cost = $row['purchase_cost'];echo $purchase_cost.'<br>'; $xmlDocument .="<SalesOrderLine>"; $xmlDocument.='<ProductID>'.$product_id.'</ProductID>';$xmlDocument.='<Quantity>'.$qty.'</Quantity>';$xmlDocument.='<SalesPrice>'.$final_price.'</SalesPrice>';$xmlDocument.='<PurchaseCost>'.$purchase_cost.'</PurchaseCost>'; // Escaping illegal characters         $xmlDocument.='</SalesOrderLine>';//$amount = $amount + $final_price;//$i++;}  $xmlDocument .="</SalesOrder>"; echo $xmlDocument."<br>";  ini_set("soap.wsdl_cache_enabled", "0");     $client = new SoapClient("http://someplace.com/CreateDB?wsdl", array(            'trace' => 1,            'exceptions' => 1,            'soap_version' => SOAP_1_1,            'encoding' => 'ISO-8859-1',            'features' => SOAP_SINGLE_ELEMENT_ARRAYS        )); $xmlvar = new SoapVar(       "<ns1:xmlDocument>".$xmlDocument."</ns1:xmlDocument>", XSD_ANYXML );$params->xmlDocument = (object)$xmlvar; $save_result = $client->AddSalesOrder($params);

I've been learning as much as I can about SOAP, but its really new to me. How do I make the xml document successfully go to the web service? The server log says that the connection is successful each time I click the submit button. But nothing is transferred to the web service.

Link to comment
Share on other sites

What is $params, and why are you casting $xmlvar as a generic object? It's already an object of the SoapVar class. It's always a good idea to log all errors. You can add this code to the top of your script to have PHP report all errors to a file called error.log in the same directory as that script, where you can check for problems with the client: error_reporting(E_ALL);ini_set('error_log', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'error.log');ini_set('html_errors', 0);ini_set('log_errors', 1);ini_set('display_errors', 0); There may also be a problem with the SOAP server, you shouldn't rule that out either.

Link to comment
Share on other sites

The error log pointed out a typo. I don't remember what it was but i took care of it and it doesn't show any new problems. According to phpinfo(), SOAP is definitely turned on. I'm at my wits end because I've never worked with SOAP before.

Edited by Dakkadakka
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...