存储从Web服务引用作为数组/数组列表检索到的数据 [英] Storing data retrieved from web service reference as array/arraylist

查看:185
本文介绍了存储从Web服务引用作为数组/数组列表检索到的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在做一个Silverlight应用程序,语言是C#,我已经成功地检索从Web服务引用的数据,并能显示它在网格视图MainPage.xaml中。但是有没有办法对我来说,我的数据存储为数组/数组列表,这样,而不是在网格视图中显示的所有列数据,我只希望它显示只有一个数据列。任何专家能帮助我在这?下面是我目前的基本code

  [OperationContract的]
  公开名单<地点>的getLocations()
  {
     DataClassesDBDataContext DB =新DataClassesDBDataContext();     VAR mlocations从位置db.locations =
                      选择位置;
     返回mlocations.ToList();
  }


解决方案

如果您使用的是WCF服务,你必须改变返回类型的能力。

在添加服务引用点击底部的高级按钮。
一个新的模式对话框打开服务引用设置那里,你可以选择集合类型为ArrayList中/阵列/列表。

现在,只要你从Web方法返回列表,您将收到您在集合类型选择之一。(这只是WCF Web服务提供(.SVC),而不是(的.asmx)

如果这不是一个选项,那么你可以在列表只是改变数组。

  VAR名单=新名单,LT;字符串> {1,2}
字符串[] arrayVal =list.ToArray();

由于问题不是很清楚,你说你只想显示在网格中的一列,你可以只返回一列数据,而从Web方法返回象

  [OperationContract的]
 公开名单<地点>的getLocations()
 {
   变种DB =新DataClassesDBDataContext();   变种mlocations =(从db.locations点¯x
                    选择新位置
                    {
                       locationColName = x.something
                    })了ToList()。
   返回mlocations;
 }

I am now doing a silverlight application, language is C# and I have successfully retrieved the data from web service reference and is able to display it on the mainpage.xaml in grid view. However is there any way for me to store my data as array/arraylist so that instead of displaying all the column data in the grid view, I only want it to display only one column of data. Any experts that can help me out on this? Below is my current basic code

  [OperationContract]
  public List<location> Getlocations()
  {
     DataClassesDBDataContext db = new DataClassesDBDataContext();

     var mlocations = from location in db.locations
                      select location;
     return mlocations.ToList();
  }

解决方案

if you are using wcf service you have a ability to change the return type.

In Add Service Reference click on the "Advanced" button at the bottom. A new modal dialog box opens "Service reference settings" there you can select "Collection Type" as Arraylist/Array/List.

Now whenever you return List from web method you will receive the one which you have selected in "Collection Type".(This is only available in wcf web service (.svc) and not (.asmx)

If that is not a option then you can just change the list to array.

var list = new List<string>{"1","2"}
string[] arrayVal =" list.ToArray();

As the question is not very clear and you say you only want to show one column in the grid you can just return one column data while returning from the web methods like

 [OperationContract]
 public List<location> Getlocations()
 {
   var db = new DataClassesDBDataContext();

   var mlocations = (from x in db.locations
                    select new location
                    {
                       locationColName = x.something
                    }).ToList();
   return mlocations;
 }

这篇关于存储从Web服务引用作为数组/数组列表检索到的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆