SOAP PHP:生成一个复杂的数组以传递给Web服务

时间:2010-10-07 09:19:39

标签: php xml soap

2个不同的问题。

我正在使用PHP SOAP类将一些XML传递给Web服务。我可以很好地生成简单的数组,并且这些数组与web服务完美配合。

1.当我尝试生成一个复杂的(数组中的数组)查询时,我遇到了错误。

2.我也不明白如何将参数(???)插入XML标签。

以下是来自webservice文档的示例XML查询的副本

<?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>

问题出现在代码的<Lines></Lines>部分。

关于XML标记参数......我需要生成这个:

<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>

我遇到问题的是

<anyType xsi:type="InvoiceLine">

即插入xsi:type =“InvoiceLine”.....

这是我目前使用的php代码。

    $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);

对不起,这个问题有点混乱 - 但正如你所看到的,这两个问题是齐头并进的。

* *收到的实际错误消息是

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

但这只是表明我提交的XML不是预期的格式。

有人可以帮忙吗?

0 个答案:

没有答案