我想知道,如何正确“消费”数据表这是在ASP.net WebService方法返回。如何使用ASP.net返回的DataTable与PHP的如何使用PHP
我对这个工作的例子:
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;
}
如果我还呼吁该Web服务在ASP.net工作正常&我得到的结果,从数据表与循环。
现在我怎么能从web服务获得这个数据表,我可以在PHP中显示/ echo?
到目前为止,我在我的PHP文件:(顺便说一句:如果我叫默认的HelloWorld()从ASP.net在PHP Web服务方法的伟大工程)
$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的结果是一起作为一个字符串。你能解决你的问题吗? – pafivi 2015-01-19 05:20:51