我只是尝试创建一个WCF来获取所有客户端详细信息。当我尝试运行WCF其得到SP数据的显示此错误:如何解决System.NullReferenceException错误
捕捉到异常:
而且也把当破发点那个时候,我看到的ID即将到来,但仍显示相同的错误。
类代码:
public class CommanCall
{
string Connection = "Data Source=USER-PC\\SQLEXPRESS;Initial Catalog=BlueEyeNewDatabase;Integrated Security=True";
public List<Client> SelectAllClient(int id)
{
List<Client> ClientList = new List<Client>();
using (var Context = new EmpSystemContext(Connection))
{
var DbResult = Context.SelectClientDetails(id);
if (DbResult != null)
{
foreach (var Row in DbResult)
{
Client clist = new Client
{
ClientName = Row.ClientName,
ClientAddress = Row.ClientAddress,
PreferredCurrency = Row.PreferredCurrency,
FirstName = Row.FirstName,
LastName = Row.LastName,
City = Row.City,
State = Row.State,
Country = Row.Country,
PostalCode = Row.PostalCode,
ContactName = Row.ContactName,
ContactNumber = Row.ContactNumber,
Email = Row.Email,
ContactEmail = Row.ContactEmail
};
ClientList.Add(clist);
}
}
}
return ClientList;
}
}
Service.svc.cs
public class Service1 : IService1
{
public static EmpSystem.Domain.CommanCall Comman;
public ListResponce<Client> GetAllClientDetailsById(int id)
{
ListResponce<Client> lstclientResp = new ListResponce<Client>();
lstclientResp.Message = "Taru kai na thai ek record find na thayo";
lstclientResp.Success = false;
int id1 = id;
List<Client> lstclient = Comman.SelectAllClient(id);
lstclientResp.Result = lstclient;
if(lstclient!=null)
{
lstclientResp.Message = "Congo hahahhah Record Find thaya";
lstclientResp.Success = true;
}
return new ListResponce<Client>
{
Message = lstclientResp.Message,
Success = lstclientResp.Success,
Result = lstclientResp.Result
};
}
}
IService文件
public interface IService1
{
[OperationContract]
[System.ServiceModel.Web.WebInvoke(Method = "GET", ResponseFormat = System.ServiceModel.Web.WebMessageFormat.Json, BodyStyle = System.ServiceModel.Web.WebMessageBodyStyle.Wrapped)]
ListResponce<Client> GetAllClientDetailsById(int id);
}
可能重复[什么是NullReferenceException,以及如何解决它?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-doi-i-fix -it) – CompuChip