简体   繁体   English

将从 web 服务参考检索到的数据存储为数组/数组列表

[英]Storing data retrieved from web service reference as array/arraylist

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. 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.如果您使用 wcf 服务,您可以更改返回类型。

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.一个新的模态对话框打开“服务参考设置”,您可以将 select“集合类型”设置为 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)现在,每当您从 web 方法返回列表时,您将收到您在“集合类型”中选择的列表。(这仅在 wcf web 服务中可用)而不是(.svcm)(。

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由于问题不是很清楚,并且您说您只想在网格中显示一列,您可以只返回一列数据,同时从 web 方法返回,例如

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

The ToArray() method used on the list should do the trick.列表中使用的 ToArray() 方法应该可以解决问题。 A simple general example is shown here:此处显示了一个简单的通用示例:

List<string> l = new List<string>();
l.Add("somedata");
. . .
string[] s = l.ToArray();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 数据结构,用于存储从Web服务检索到的客户端数据 - Data structure to store client data retrieved from a Web Service 存储和报告从API检索到的数据 - Storing and Reporting on data retrieved from an API 基于从文本文件中检索到的数据在多维数组列表中进行排序和存储 - Sorting and Storing in a Multidimensional Array List based on the data retrieved from a text file 以编程方式创建和存储从Web服务检索为byte []数据的图像作为Umbraco中的媒体项 - Programmatically create and store images retrieved as byte[] data from a web service as media items in Umbraco 使用C#从Web服务存储XML - Storing XML from a web service in C# 在Windows Phone 7应用程序的隔离存储中存储从Web服务接收的数据 - storing data received from web service in isolated storage in windows phone 7 application 从Web服务返回的DataSet对象数组中获取数据 - Getting data from array of DataSet objects returned from web service C#将数据从输入存储到Class内的arraylist - C# storing data from input to arraylist inside Class 如何从代码引用非现场Web服务 - How to reference an offsite web service from code 如何使用从Web服务获得的arraylist填充下拉列表 - How to fill a dropdownlist with arraylist that I get from a web service
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM