Click here to Skip to main content
15,888,251 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
I have made a web service which returns client name and id of all the clients from my client table.
now i have added reference of the service in my web application.
now i want to return client name and client id in the grid view in my application.
can anyone help.
below is my code:
Imyservice
C#
[ServiceContract]
   public interface Imyservice
   {
       [OperationContract]

       List<ClientDetails> getClient();

   }

myservice.cs
C#
public class myservice : Imyservice
   {
     public  List<ClientDetails> getClient()
       {
           List<ClientDetails> client = new List<ClientDetails>();
           SysXAppDBEntities app = new SysXAppDBEntities();
            var sql = (from pro in app.Clients
                    select new ClientDetails()
                    {
                        ClientID = pro.ClientID,
                        ClientName = pro.ClientName

                    });
         return sql.ToList();

               }

           }

ClientDetails :
C#
[DataContract]
    public class ClientDetails
    {

        [DataMember]
        public string ClientName
        {
            get;
            set;

        }

        [DataMember]
        public Int32 ClientID
        {
            get;
            set;

        }

        [DataMember]
        public Int32 TenantID
        {
            get;
            set;

        }

    }
Posted
Updated 22-May-13 23:10pm
v2
Comments
vijay__p 23-May-13 5:28am    
Can you be more clear. Are you having problem in Grid binding or returning data from service ?
pree_kh 23-May-13 5:37am    
@vijay__p: i am having problem on returning data from service

1 solution

found the solution:
C#
 protected void Page_Load(object sender, EventArgs e)
        {
            ServiceReference1.ImyserviceClient svc = new ServiceReference1.ImyserviceClient();
            IList<clientdetails> customers = svc.getClient();
            GridView1.DataSource = customers;
            GridView1.DataBind();

        }
</clientdetails>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900