【问题标题】:How to consume WebService returned DataTable from ASP.net with PHP如何使用 PHP 使用从 ASP.net 返回的 WebService 数据表
【发布时间】: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


【解决方案1】:

你试过了吗:

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

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

【讨论】:

    【解决方案2】:

    我尝试了类似的方法并且效果很好。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-07
      • 2017-03-26
      • 2015-06-04
      • 1970-01-01
      相关资源
      最近更新 更多