簡體   English   中英

從PHP客戶端將數組傳遞給SOAP服務

[英]passing array to SOAP service from PHP client

我在將數據從PHP客戶端傳遞到SOAP服務時遇到問題。

根據:期望從SOAP服務獲得以下內容(將傳遞)

invoiceCreateFullData.incallfilename[0]:    
invoiceCreateFullData.incallfileno[0]:  
invoiceCreateFullData.inservices[0].item[0].inListName[0]:  
invoiceCreateFullData.inservices[0].item[0].inListPrice[0]: 
invoiceCreateFullData.inservices[0].item[0].inListQuantity[0]:  
invoiceCreateFullData.inservices[0].item[0].inListTotalAmount[0]:   
invoiceCreateFullData.inservices[0].item[0].inListTaxRate[0]:   
invoiceCreateFullData.inservices[0].item[0].inListFinalTax[0]:  
invoiceCreateFullData.inservices[0].item[0].inListFinalPrice[0]:    
invoiceCreateFullData.inservices[0].item[1].inListName[0]:  
invoiceCreateFullData.inservices[0].item[1].inListPrice[0]: 
invoiceCreateFullData.inservices[0].item[1].inListQuantity[0]:  
invoiceCreateFullData.inservices[0].item[1].inListTotalAmount[0]:   
invoiceCreateFullData.inservices[0].item[1].inListTaxRate[0]:   
invoiceCreateFullData.inservices[0].item[1].inListFinalTax[0]:  
invoiceCreateFullData.inservices[0].item[1].inListFinalPrice[0]:    
invoiceCreateFullData.incharges[0].item[0].inChargeName[0]:

這就是我試圖在PHP客戶端上收集它的方式:

 foreach  (  $invoice[ 'itemized_list' ] as $lines ) {

[..snip..]

        $single_items = array(
                "inListName"            => $lines['name'],
                "inListPrice"           => $px_price ,
                "inListQuantity"        => $px_quantity,
                "inListTotalAmount"     => $px_price_total,
                "inListTaxRate"         => $px_tax,
                "inListFinalTax"        => $final_tax,
                "inListFinalPrice"      => ( $px_price_total + $final_tax )
                );
         array_push( $param_items, $single_items );
}

[..snip ..]

        $SOAP_Connection_Address = 'http://conmony.wsdl';

        $TOTALDUE = $in_TotLineItemPrice + $in_TotLineItemTax + $in_TotChangeAmt + $in_TotChangeTax - $in_TotDiscount;

        $parameters     = array("item" =>
                                     array(
                                        "inLogonID"             => $in_LogonID,

                    [..snip..]

                              "inservices" =>  array("item" => $param_items ),
                              "incharges"  => $param_charges,
                              "indiscounts"=> $param_discounts
                               );

但是當我在SERVER端檢查長度時,我得到的是零(0)

 sprintf(out_buffer, "SERVICES OFF-SIZE %d  SERVICES SIZE %d ",  inservices.__offset,  inservices.__size );
 print_err(__FILE__, __LINE__, out_buffer);

在執行var_dump時,我得到以下信息:

[..snip ..]

["inservices"]=> array(1) { ["item"]=> array(4) { [0]=> array(7) { ["inListName"]=> string(11) "sweep drive" ["inListPrice"]=> float(12) ["inListQuantity"]=> int(1) ["inListTotalAmount"]=> float(12) ["inListTaxRate"]=> int(0) ["inListFinalTax"]=> int(0) ["inListFinalPrice"]=> float(12) } [1]=> array(7) { ["inListName"]=> string(11) "trim bushes" ["inListPrice"]=> float(5) ["inListQuantity"]=> int(1) ["inListTotalAmount"]=> float(5) ["inListTaxRate"]=> int(0) ["inListFinalTax"]=> int(0) ["inListFinalPrice"]=> float(5) } [2]=> array(7) { ["inListName"]=> string(29) "CS Major Mow, cut, blow, trim" ["inListPrice"]=> float(60) ["inListQuantity"]=> int(1) ["inListTotalAmount"]=> float(60) ["inListTaxRate"]=> int(0) ["inListFinalTax"]=> int(0) ["inListFinalPrice"]=> float(60) } [3]=> array(7) { ["inListName"]=> string(30) "RM Mow lawn, trim, sweep, blow" ["inListPrice"]=> float(80) ["inListQuantity"]=> int(1) ["inListTotalAmount"]=> float(80) ["inListTaxRate"]=> int(0) ["inListFinalTax"]=> int(0) ["inListFinalPrice"]=> float(80) } } }

有人可以提示我出什么問題嗎?

謝謝!


添加更多...

生成WSDL的定義文件(按比例縮小)

//gsoap am service name: conmony
//gsoap am service style: document
//gsoap am service encoding: literal
//gsoap am service namespace: urn:monyServer
//gsoap am service location: http://99.49.227.50:8080
//gsoap am schema  namespace: urn:conmony
//gsoap ns service method-action: invoiceCreateFullData ""

[... snip ...]

typedef struct          am__struct_DBDISCOUNTRET{
        xsd__string     inDiscountDesc;
        xsd__double     inDiscountAmount;
};

typedef struct          am__DISCOUNTRETItems {
        struct am__struct_DBDISCOUNTRET  *__ptr;
        int __size;
        int __offset;
};

typedef struct          am__struct_DBSERVICELISTRET{
        xsd__string     inListName;
        xsd__double     inListPrice;
        xsd__int        inListQuantity;
        xsd__double     inListTotalAmount;
        xsd__double     inListTaxRate;
        xsd__double     inListFinalTax;
        xsd__double     inListFinalPrice;
};

typedef struct          am__SERVICELISTRETItems {
        struct am__struct_DBSERVICELISTRET  *__ptr;
        int __size;
        int __offset;
};


typedef struct          am__struct_DBCHARGESRET{
        xsd__string     inChargeName;
        xsd__double     inChargePrice;
        xsd__double     inChargeTotalAmount;
        xsd__double     inChargeTaxRate;
        xsd__double     inChargeFinalTax;
        xsd__double     inChargeFinalPrice;
};

typedef struct          am__CHARGESRETItems {
        struct am__struct_DBCHARGESRET  *__ptr;
        int __size;
        int __offset;
};


int am__invoiceCreateFullData(
        xsd__string  inLogonID,
        xsd__string  inLogonPassword,
        xsd__string  inCustomerEMail,
        xsd__int     inServiceAddrID,
        xsd__double  inSvcGoogleLat,
        xsd__double  inSvcGoogleLong,
        xsd__string  inWPLookupInvoiceID,
        xsd__int     inWPInvoiceID,
        xsd__int     inWPInternalInvoiceID,
        xsd__string  inSubject,

    [ ... snip ... ]

        xsd__int     incallpid,
        xsd__string  incallfilename,
        xsd__int     incallfileno,
        struct       am__SERVICELISTRETItems inservices,
        struct       am__CHARGESRETItems incharges,
        struct       am__DISCOUNTRETItems indiscounts,
        struct am__TENANTRETItems *DBListing);

更多服務器端代碼(按比例縮小):

int am__invoiceCreateFullData (
        struct soap  *soap,
        xsd__string  inLogonID,
        xsd__string  inLogonPassword,
        xsd__string  inCustomerEMail,
        xsd__int     inServiceAddrID,
        xsd__double  inSvcGoogleLat,
        xsd__double  inSvcGoogleLong,
        xsd__string  inWPLookupInvoiceID,
        xsd__int     inWPInvoiceID,
        xsd__int     inWPInternalInvoiceID,
        xsd__string  inSubject,

    [... snip ...]

        xsd__int     inCredit,
        xsd__string  incallhost,
        xsd__int     incallpid,
        xsd__string  incallfilename,
        xsd__int     incallfileno,
        struct       am__SERVICELISTRETItems    inservices,
        struct       am__CHARGESRETItems        incharges,
        struct       am__DISCOUNTRETItems       indiscounts,
        struct       am__TENANTRETItems         *DBListing)
 {

 soap -> double_format="%lf";

 char out_buffer[500];


 sprintf(out_buffer,
                 "SERVICES OFF-SIZE %d OFF-CHARGES %d OFF-DISCOUNTS %d SERVICES SIZE %d CHARGES %d DISCOUNTS %d ",
                 inservices.__offset, incharges.__offset,  indiscounts.__offset, inservices.__size, incharges.__size,  indiscounts.__size );

 print_err(__FILE__, __LINE__, out_buffer);

 int x = 0;

 for ( x = 0; x <  inservices.__size; x++ )
        {
        sprintf(out_buffer, "WHAT WAS PASSED IN - %s \n", inservices.__ptr[ inservices.__size - x - 1 ].inListName);

        print_err(__FILE__, __LINE__, out_buffer);
        }

將參數傳遞給SOAP服務有什么問題?

謝謝。

找到了我自己的問題的答案。 我對代碼進行了更改(因此並不那么復雜),但是要做的事情是這樣的:

$param_items['item'][$count] = array(
                "inListName"        => $lines['name'],
                "inListPrice"       => $px_price ,
                 [... snip ...] ));

這是一個顯而易見的答案-我對PHP方面有點陌生,認為解決方案會困難得多。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM