简体   繁体   中英

passing array to SOAP service from PHP client

I am having problems passing data to a SOAP service from a PHP client.

According to: The following is expected from the SOAP service (to be passed in)

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

This is how I am trying to collect it on the PHP client side:

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

But when I check out the length on the SERVER side, I just get ZERO (0)

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

When doing a var_dump, I get the following:

[..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) } } }

Can someone give me a hint as to what is going wrong?

Thanks!


adding more...

DEFINITION FILE TO GENERATE WSDL (scaled down)

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

More Server Side Code (scaled down):

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

What is the problem with passing the parameters to the SOAP service?

Thanks.

Found the answer to my own problem. I made changes to the code (so it was not so complex) but the thing that did it was this:

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

This was such an obvious answer - I am kinda new to the PHP side of things and thought the solution would have been much harder ....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM