开发者

SOAP PHP : Generating a complex array to pass to web service

2 distinct problems.

I'm using the PHP SOAP class to pass some XML to a webservice. I can generate simple arrays just fine, and these work perfectly with the webservice.

1.When I try to generate a complex (arrays within arrays) query I'm getting errors.

2.Also I don't understand how to insert a parameter(???) into an XML tag.

Below is a copy of the sample XML query from the webservice documentation

<?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:Body>
    <InsertInvoice xmlns="KashFlow">
      <UserName>string</UserName>
      <Password>string</Password>
      <Inv>
        <InvoiceDBID>int</InvoiceDBID>
        <InvoiceNumber>int</InvoiceNumber>
        <InvoiceDate>dateTime</InvoiceDate>
        <DueDate>dateTime</DueDate>
        <Customer>string</Customer>
        <CustomerID>int</CustomerID>
        <Paid>int</Paid>
        <CustomerReference>string</CustomerReference>
        <EstimateCategory>string</EstimateCategory>
        <SuppressTotal>int</SuppressTotal>
        <ProjectID>int</ProjectID>
        <CurrencyCode>string</CurrencyCode>
        <ExchangeRate>decimal</ExchangeRate>
        <ReadableString>string</ReadableString>
        <Lines>
开发者_运维技巧          <anyType />
          <anyType />
        </Lines>
        <NetAmount>decimal</NetAmount>
        <VATAmount>decimal</VATAmount>
        <AmountPaid>decimal</AmountPaid>
        <CustomerName>string</CustomerName>
      </Inv>
    </InsertInvoice>
  </soap:Body>
</soap:Envelope>

The problem is occuring in the <Lines></Lines> section of the code.

With regards to the XML tag parameter... I need to produce this :

<Lines>
<anyType xsi:type="InvoiceLine">
 <Quantity>1</Quantity>
 <Description>Description here</Description>
 <Rate>99</Rate>
 <ChargeType>0</ChargeType>
 <VatRate>0</VatRate>
 <VatAmount>0</VatAmount>
 <ProductID>0</ProductID>
 <LineID>0</LineID>
 </anyType>
</Lines>

The bit that I am having problems with is

<anyType xsi:type="InvoiceLine">

namely inserting the xsi:type="InvoiceLine" .....

Here's the php code I'm currently using.

    $invoice_array = array 
(
'InvoiceDBID' => "",
'InvoiceNumber' => 1,
'InvoiceDate' => date("c",strtotime($invoice_data['date_purchased'])),
'DueDate' => date("c",strtotime($invoice_data['date_purchased'])),
'Customer' => $invoice_data['customers_name'],
'CustomerID' => $KFcust->CustomerID,
'Paid' => 0,
'CustomerReference' => "",
'EstimateCategory' => "",
'SuppressTotal' => 0,
'ProjectID' => 0,
'CurrencyCode' => 0,
'ExchangeRate' => 1,
'NetAmount'=> 0,
'ReadableString' =>"this invoice created by osc for order ".$invoice_data['orders_id']);

foreach($line_data as $line)
{
$line_array[] = array(
'Quantity'=>$line['products_quantity'],
'Description'=>$line['products_name'],
'Rate'=>$line['products_tax'],
'ChargeType'=>0,
'VatAmount'=>$totals_data['ot_tax']['value'],
'VatRate'=>$line['products_tax'],
'Sort'=>1,
'ProductID'=>$line['products_id']);
}

$invoice_array['Lines']=array('anyType'=> array('_'=>$line_array, 'xsi:type'=>"InvoiceLine"));
$invoice_array['Netamount']=$totals_data['ot_subtotal']['value']+$totals_data['ot_shipping']['value'];
$invoice_array['VATAmount']=$totals_data['ot_tax']['value'];
$invoice_array['AmountPaid']=$totals_data['ot_total']['value'];
$invoice_array['CustomerName']=$invoice_data['customers_name'];

$invID = $client->createInvoice($invoice_array);

Sorry this inquiry is a little muddled - but as you can see, both of these problems go hand in hand.

**The actual error message received is

Unable to cast object of type 'System.Xml.XmlNode[]' to type 'KashFlow.InvoiceLine'.

But this is just an indication that I am submitting XML that is not in the expected format.

Can anyone help please?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜