我的asmx网络服务中有一个web方法,如下所示:
[WebMethod]
public DataTable ItemsReturn()
{
using (Enteties dbc= new CRMEntities())
{
var AccpaccItems = (from c in crm.ItemsTable
where c.INACTIVE == 0
select new { c.ItemNo, c.ItemDesc, c.ItemAmount }).ToList();
DataTable dtItems = new DataTable("Items");
dtItems.Columns.Add("cValue");
dtItems.Columns.Add("cDescription");
dtItems.Columns.Add("cDefaultPrice");
foreach (var item in AccpaccItems)
{
DataRow drItem = dtItems.NewRow();
drItem["cValue"] = item.ItemNo;
drItem["cDescription"] = item.ItemDesc;
drItem["cDefaultPrice"] = item.ItemAmount ;
dtItems.Rows.Add(drItem);
}
return dtItems;
}
}
我的客户端有一个PHP站点,我在其中调用Web服务。
<?php
$client = new SoapClient('http://xxxxxx/myservice.asmx?WSDL', array('trace' => 1));
var_dump($client->ItemsReturn());
?>
现在,一切都运行良好,但我想知道在数组中以PHP的形式返回这些值的最佳方法是什么? 所以它看起来像这样:
<Items diffgr:id="Items1" msdata:rowOrder="0" diffgr:hasChanges="inserted">
<cValue>PSREZ.5IN1</cValue>
<cDescription>Partner Software 5in1</cDescription>
</Items>
<Items diffgr:id="Items2" msdata:rowOrder="1" diffgr:hasChanges="inserted">
<cValue>PSREZ.ADDEM</cValue>
<cDescription>Partner Additional Employees</cDescription>
</Items>
<Items diffgr:id="Items3" msdata:rowOrder="2" diffgr:hasChanges="inserted">
<cValue>PSREZ.RBIA</cValue>
<cDescription>Partner BIC Advanced</cDescription>
</Items>
另外,webserice中的DataTable是返回数据而不是DataSet的最佳方式吗?
感谢。