Arti
Arti

Reputation: 3071

Consume web service returning list

I have a web service with webmethod like this:

Webservice:

   [WebMethod]
    public List<ProcessQueue> GetTasks(int ShopId)
    {
        List<ProcessQueue> p = new List<ProcessQueue>();
        p.Add(new ProcessQueue {shopId="shop1", process="process1"});
        p.Add(new ProcessQueue {shopId="shop2", process="process2"});   
        return p;
    }


    public class ProcessQueue
    {
        public string shopId { get; set; }
        public string process { get; set; }
    }

I also have a windows form application which is consuming the web service:

I followed the steps described in Consume a web service

Windows form:

using (var svc = new Service1SoapClient())
{
    var result = svc.GetTasks(7);
    MessageBox.Show(result.ToString());
}

Right now I am able to consume the web service but only problem I am facing is I cannot get the result as a string in my windows form application.

How would I do that. Any help?

Upvotes: 0

Views: 1428

Answers (2)

Arti
Arti

Reputation: 3071

I managed to get the desired result by doing this in winform application:

using (var svc = new Service1SoapClient())
{
   var result = svc.GetTasks(7);
   List<ProcessQueue> Processqueue=result.ToList<ProcessQueue>();
   foreach (ProcessQueue process in Processqueue)
   {
      MessageBox.Show(process.shopId);
   }
}

Upvotes: 0

Fanda
Fanda

Reputation: 3786

On the client side you have to normally iterate on result, as on list at server side (you have the same type (probably) on the client:

using (var svc = new Service1SoapClient())
{
    var result = svc.GetTasks(7);
    foreach (var item in result)
    {
        textBoxName.AppendText(String.Format("ShopId: {0}, Process: {1}\n", item.shopId, item.process));
    }
}

Upvotes: 1

Related Questions