我有一个简单的 WCF 应用程序。在文件 IService.cs 中:
namespace WcfService1
{
[ServiceContract]
public interface IService
{
[OperationContract]
List<ActiveSP> GetActiveSP();
}
[DataContract]
public class ActiveSP
{
[DataMember]
public string DESCR { get; set; }
}
}
在文件 Service.svc.cs 中:
namespace WcfService1
{
public class Service : IService
{
SqlConnection Conn;
SqlCommand Cmd;
public Service()
{
Conn = new SqlConnection("Data Source=myweb;Initial Catalog=PeopleSoft;Integrated Security=True;");
}
public List<ActiveSP> GetActiveSP()
{
Conn.Open();
Cmd = new SqlCommand();
Cmd.Connection = Conn;
Cmd.CommandText = "Select DESCR from myTable"; // return column (varchar type)
SqlDataReader Reader = Cmd.ExecuteReader();
List<ActiveSP> 1stSP = new List<ActiveSP>(); // wrong here
while (Reader.Read())
{
// blah
}
}
}
}
错误请看图:
谢谢。