如何使用PHP从Web.net返回DataService返回DataTable

时间:2013-03-25 23:06:54

标签: php asp.net web-services datatable

我想知道,如何正确“使用”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中也称这个网络服务工作正常&我从带有循环的数据表获得结果。

现在我如何从我可以在PHP中显示/回显的webservice获取此数据表?

到目前为止,我已经在我的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);

结果是: php error

2 个答案:

答案 0 :(得分:0)

你试过这个:

$params->search = "car"; //this is search variable

它对我很好,但我不知道如何处理行和列: - (

答案 1 :(得分:0)

我尝试过类似的东西并且工作正常。

$client = new SoapClient("http://localhost/WebService.asmx?WSDL");
$result = $client->__soapCall("functionName", array($SoapCallParameters));

var_dump($result->functionNameResult);