简体   繁体   English

从PHP客户端将数组传递给SOAP服务

[英]passing array to SOAP service from PHP client

I am having problems passing data to a SOAP service from a PHP client. 我在将数据从PHP客户端传递到SOAP服务时遇到问题。

According to: The following is expected from the SOAP service (to be passed in) 根据:期望从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]:

This is how I am trying to collect it on the PHP client side: 这就是我试图在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
                               );

But when I check out the length on the SERVER side, I just get ZERO (0) 但是当我在SERVER端检查长度时,我得到的是零(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: 在执行var_dump时,我得到以下信息:

[..snip..] [..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) 生成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);

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? 将参数传递给SOAP服务有什么问题?

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 .... 这是一个显而易见的答案-我对PHP方面有点陌生,认为解决方案会困难得多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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