0

I just try to create one of WCF to get all client details. When I try to run that WCF which get data from SP its show this error:

service error

Caught exception:

caught exception

And also when put break point that time I see the ID is coming but still error showing same.

Class code:

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 file

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);
}
lorond
  • 3,856
  • 2
  • 37
  • 52
Herry
  • 77
  • 1
  • 12
  • 1
    Possible duplicate of [What is a NullReferenceException, and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – CompuChip Jul 22 '16 at 14:09

1 Answers1

2

From the code you posted I can suggest you forgot to create an instance of CommanCall. Field Comman is reference type which is by default initialized with null. So NullReferenceException thrown when you trying to call member of null. Create an instance for Comman, for example:

public static EmpSystem.Domain.CommanCall Comman = new EmpSystem.Domain.CommanCall();

If field Comman initialized somewhere else, please, show stack trace of exception you caught.

lorond
  • 3,856
  • 2
  • 37
  • 52