Sign in to follow this  
Followers 0
Dakkadakka

How do I use SOAP to transmit an XML?

1 post in this topic

I'm trying to get a string representative of an XML sheet send to a web service. This is how sales orders will be submitted online. The web service stores the order in a database. The web service is meant to take in a string to be read as XML. PHP and SOAP can't send XML to a web service as is and I'm having trouble working around this.First here is the code that generates the string.$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>'; $xmlDocument.='</SalesOrderLine>'; //$amount = $amount + $final_price; //$i++; } $xmlDocument .="</SalesOrder>"; I conclude by transmitting the string, but something is wrong. ini_set("soap.wsdl_cache_enabled", "0");$client = new SoapClient("http://12.34.56.78:blahblah/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'm quote new to working with SOAP, but I'm really stuck with this. How do I fix this? The only alternative is using brute force and doing the insertion myself. I would love nothing more but to do that, but I have to use the webservice, because it will not only write to the MySQL database, it will write to Quickbooks.

Share this post


Link to post
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
Sign in to follow this  
Followers 0