【发布时间】:2013-03-15 14:59:18
【问题描述】:
我想知道,如何正确“消费”在 ASP.net WebService 方法中返回的 DataTable。
我正在研究这个例子:
ASP.net WEBSERVICE:
[WebMethod]
public DataTable searchDatabase(string search)
{
SqlConnection conn = null;
SqlDataReader rdr = null;
conn = new
SqlConnection("Data Source=ASUSX301A\\MSSQLINSTANCE;Initial Catalog=db_sp_vaje;Integrated Security=True;Pooling=False");
conn.Open();
// 1. create a command object identifying
// the stored procedure
SqlCommand cmd = new SqlCommand(
"dbo.sp_iskanje", conn); //here is my stored procedure which works 100%
// 2. set the command object so it knows
// to execute a stored procedure
cmd.CommandType = CommandType.StoredProcedure;
// 3. add parameter to command, which
// will be passed to the stored procedure
cmd.Parameters.Add(
new SqlParameter("@myInput", search));
// execute the command
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataTable dt = new DataTable();
dt.TableName = "oglasi";
dt.WriteXml(@"path", true);
da.Fill(dt);
// iterate through results, printing each to console
return dt;
}
如果我在 ASP.net 中也调用此 Web 服务,则可以正常工作,并且我会从带有循环的数据表中获得结果。
现在如何从 web 服务中获取可以在 PHP 中显示/回显的数据表?
到目前为止,我的 PHP 文件中有这个:(顺便说一句:如果我在 PHP 中从 ASP.net 调用默认的 HelloWorld() webservice 方法效果很好)
$client = new SoapClient("http://localhost:10994/WebService.asmx?WSDL");
$params->Param1 = "car"; //this is search variable
$result = $client->searchDatabase($params)->searchDatabaseResult;
print_r ($result);
结果是:
【问题讨论】:
-
嗨!很长一段时间,但我正在从事上述项目。我的问题是如何操作返回的 DataTable 的列和行。我可以成功调用该函数,但 DataTable 的结果是一个字符串。你能解决你的问题吗?
标签: php asp.net web-services datatable