我怎么能看到数据表是从webservice方法返回的

时间:2010-01-06 09:17:18

标签: asp.net jquery ajax web-services

我正在尝试使用来自Web服务方法的数据表。当它是一个字符串数据时,我可以看到返回值。 这是我的代码,它返回一个警告 hatada:null

 $.ajax(
            {
                type: 'POST',
                url: 'http://localhost:40764/HastaTahlilUyariServisi.asmx/Hello',
                data: "{_sTcKimlikNo: '111111111111', _iKlinikKodu:121212, _bAy:12, _iYil:2009}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(ajaxCevap) {
                    alert('basarili: ' + ajaxCevap); //$('#dv').html(ajaxCevap.d);
                },
                error: function(xhr, status) {                   
                    alert("hatada:" + xhr.responseXML);
                },
                beforeSend: function() {
                    alert('gonderilecek');
                },
                afterSend: function() {
                    alert('gonderildi');
                },
                complete: function(xhr, status) {
                    if (status == 'success')
                        alert('success' + $.httpData(xhr));
                }
            }

这是我的网络服务方法:

  [WebMethod]
    public DataTable Hello(string _sTcKimlikNo, int _iKlinikKodu, byte _bAy, int _iYil)
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("ad");
        DataRow rw = dt.NewRow();
        rw[0] = _sTcKimlikNo + " " + _iKlinikKodu + " " + _bAy + " " + _iYil;
        return dt;
    }

如何从webservice方法中查看数据表? 提前谢谢。

2 个答案:

答案 0 :(得分:1)

没有序列化问题,只需命名数据表即可解决问题。

public DataTable LineChrt() {
  string query = "select m.class,sum(m.plannedvisits)" + 
    "plannedvisits,sum(m.actualvisits) actualvisits from vw_MTD_TgtVsAct_Calls1 m " +
    "where 1=1 and m.class in ('A','B','C')  and m.month = 6 " +
    "group by m.class";
  string constr = System.Configuration
    .ConfigurationSettings.AppSettings["PocketDCR"];
  DataTable data = new DataTable();
  SqlDataAdapter LCData = new SqlDataAdapter(query,constr);
  LCData.Fill(data);
  data.TableName = "ChartData";
  return data;
}

答案 1 :(得分:0)

由于序列化问题,我认为您无法从Web服务返回DataTable。这篇Microsoft文章建议返回一个DataSet:
Problems using an XML Web service that returns a DataTable