从PHP客户端

时间:2016-02-22 20:38:10

标签: php arrays soap

我在从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端的长度时,我得到ZERO(0)

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

执行var_dump时,我得到以下内容:

[..剪断..]

["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服务有什么问题?

感谢。

1 个答案:

答案 0 :(得分:0)

找到我自己问题的答案。我对代码进行了更改(所以它不是那么复杂),但做到这一点的是:

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

这是一个非常明显的答案 - 我对PHP方面有些新意,并认为解决方案会更难......