Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用web服务返回列表_C#_Winforms_Web Services_Class - Fatal编程技术网

C# 使用web服务返回列表

C# 使用web服务返回列表,c#,winforms,web-services,class,C#,Winforms,Web Services,Class,我有一个使用webmethod的web服务,如下所示: Webservice: [WebMethod] public List<ProcessQueue> GetTasks(int ShopId) { List<ProcessQueue> p = new List<ProcessQueue>(); p.Add(new ProcessQueue {shopId="shop1", process="proces

我有一个使用webmethod的web服务,如下所示:

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; }
    }
现在我可以使用web服务,但我面临的唯一问题是无法在windows窗体应用程序中以字符串形式获取结果


我该怎么做呢。有什么帮助吗?

在客户端,您通常必须迭代结果,就像在服务器端的列表中一样(您在客户端上的类型(可能是相同的):

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));
    }
}

通过在winform应用程序中执行以下操作,我成功地获得了所需的结果:

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);
   }
}
使用(var svc=new Service1SoapClient())
{
var result=svc.gettask(7);
List Processqueue=result.ToList();
foreach(ProcessQueue中的ProcessQueue进程)
{
MessageBox.Show(process.shopId);
}
}

您想如何将列表转换为字符串?我想在winform中获取shopId和process的值,如何实现?我不想将列表转换为字符串。好的,假设您的服务返回了2行,您期望的输出字符串是什么?我自己得到了解决方案。请查看我的更新
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);
   }
}