在asp.net中使用wcf服务返回数据表的问题 [英] problem in returning datatable using wcf service in asp.net

查看:92
本文介绍了在asp.net中使用wcf服务返回数据表的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好......

我有一个wcf服务,我从中返回一个数据表。我的代码是......

 [ServiceContract] 
public interface IMyWCFService
{
[OperationContract]
Student StudentRecord();
}

[DataContract]
public class 学生
{
[DataMember]
public DataTable StudentTable
{
获得;
set ;
}
}



和其他文件代码是......

  public  Student StudentRecord()
{
Student st = new Student();
DataTable dt = new DataTable();
SqlConnection con = new SqlConnection( data source = ggsys03; initial catalog = Test; integrated security = true);

SqlDataAdapter da = new SqlDataAdapter( select * from studentInfo,con);
da.Fill(dt);
st.StudentTable = dt;
return st;

}



当我使用它时会出错...



   mscorlib.dll中出现System.ServiceModel.CommunicationException类型的异常,但未在用户代码中处理

附加信息:收到对http:// localhost:49314 / MyWCFService.svc的HTTP响应时发生错误。这可能是由于服务端点绑定未使用HTTP协议。这也可能是由于服务器中止了HTTP请求上下文(可能是由于服务关闭)。有关详细信息,请参阅服务器日志。


如何解决这个问题...

解决方案

为DataTable命名,如新的 DataTable(Students);



-KR


像这样使用



首先增加你的bufferrecive大小



验证这一点



https:// stackoverflow。 com / questions / 5337412 / buffer-size-in-wcf-service [ ^ ]



仍然会发生这样的事情,我希望它不起作用



 [ServiceContract] 
public interface IMyWCFService
{
[OperationContract]
DataTable StudentRecord();
}

// [DataContract]
// 公共类学生
// {
// [DataMember ]
// public DataTable StudentTable
// {
// get;
// set;
// }
// }









公共DataTable StudentRecord()

{

// Student st = new Student();

DataTable dt = new DataTable();

SqlConnection con = new SqlConnection(data source = ggsys03;初始目录=测试; integrated security = true);



SqlDataAdapter da = new SqlDataAdapter(select * from studentInfo,con);

da.Fill (dt);

//st.StudentTable = dt;

返回dt;



}


hello ...
i have a wcf service from which i am returning a data table . my code is ...

[ServiceContract]
public interface IMyWCFService
{	
    [OperationContract]
    Student StudentRecord();
}

[DataContract]
public class Student
{
    [DataMember]
    public DataTable StudentTable
    {
        get;
        set;
    }
}


and the other file code is ...

public Student StudentRecord()
{
    Student st = new Student();
    DataTable dt = new DataTable();
    SqlConnection con = new SqlConnection("data source=ggsys03 ; initial catalog=Test ; integrated security=true");

    SqlDataAdapter da = new SqlDataAdapter("select * from studentInfo", con);
    da.Fill(dt);
    st.StudentTable = dt;
    return st;

}


when i using this it gives error ...

"An exception of type 'System.ServiceModel.CommunicationException' occurred in mscorlib.dll but was not handled in user code

Additional information: An error occurred while receiving the HTTP response to http://localhost:49314/MyWCFService.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details."


how to solve out this problem ...

解决方案

Give a name to a DataTable Like new DataTable("Students");

-KR


use like this

first increase your bufferrecive size

verify this

https://stackoverflow.com/questions/5337412/buffer-size-in-wcf-service[^]

Still it happen do like this, i hope it ill work

[ServiceContract]
public interface IMyWCFService
{
    [OperationContract]
    DataTable StudentRecord();
}

//[DataContract]
//public class Student
//{
    //[DataMember]
    //public DataTable StudentTable
    //{
     //   get;
       // set;
    //}
//}





public DataTable StudentRecord()
{
//Student st = new Student();
DataTable dt = new DataTable();
SqlConnection con = new SqlConnection("data source=ggsys03 ; initial catalog=Test ; integrated security=true");

SqlDataAdapter da = new SqlDataAdapter("select * from studentInfo", con);
da.Fill(dt);
//st.StudentTable = dt;
return dt;

}


这篇关于在asp.net中使用wcf服务返回数据表的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆