0

I'm having trouble passing a parameter list in php in a web service c #.

The Web services in c# is as follows:

[WebMethod ()]
public string IncluirOrcamento (List <ProdutosOrcamento> Products)
{
...
}

Where ProdutosOrcamento is a class in c# represented in this way ..

public class ProdutosOrcamento
{
         public string ProductCode {get; sets;}
         public Nullable <double> quantity {get; sets;}
}

Done this way in php ...

<? php
require_once ('/ lib / nusoap.php');

$ array = array ("Product" => array ("ProdutosOrcamento" => array (
'ProductCode' => '44 ',
'quantity' => '2 ')
"ProdutosOrcamento" => array (
'ProductCode' => '55 '​​,
'quantity' => '13 ')));

/ / print_r ($ array);
$ wsdl = "http://localhost:33328/KasviService.asmx?WSDL";
$ function = "IncluirOrcamento";
$ client = new nusoap_client ("http://localhost:33328/KasviService.asmx?WSDL", array ('location' => 'http://localhost:33328/KasviService.asmx?WSDL'));

$ result = $ client-> call ("IncluirOrcamento", $ array);

if ($ client-> fault) {
print_r ($ result);
else {}
     $ err = $ client-> getError ();
if ($ err) {
echo 'Error <h2> </ h2> <pre>'. $ err. '</ pre>';
     else {}
print_r ($ result);
     }
}
?>

I pass an array of objects, but my problem is that only considered the last object in the array, and I can not build a list with lots of objects. Does anyone know how to pass a list of objects in php web services for C #?

4

1 回答 1

0

首先,我假设您的代码和数据中的额外空格只是复制/粘贴格式问题,因为如所写,您的代码会产生致命错误。

假设额外的空格是唯一的复制/粘贴问题,问题是您通过重新使用相同的键来覆盖数组数据:

$array = array(
    "Product" => array(
        "ProdutosOrcamento" => array( // key:  ProdutosOrcamento
            'ProductCode' => '44 ',
            'quantity' => '2 ')  // You're also missing a comma here...
        "ProdutosOrcamento" => array( // key:  ProdutosOrcamento again!
            'ProductCode' => '55 '​​,
            'quantity' => '13 ')
    )
);

所以表示 ProductCode 55 的数组将覆盖表示 ProductCode 44 的数组。

于 2013-06-24T23:48:58.543 回答