将列表传递给JSON Web服务

时间:2014-06-27 13:50:20

标签: c# .net web-services

我正在尝试将此列表传递给JSON列表服务,但它只返回最后一个项目,但是对于对象数量重复9次。但是当我从循环中调用dll中的代码时它在循环中很好但是当从web服务调用它时并不是这样我认为它更多地与serialize方法有关吗?

public List<ViewPresentation> GetColumnsFromXml(string ColumnsXmlString, string xpath)
{
    XDocument doc = XDocument.Parse(ColumnsXmlString);
    XNamespace ns = XNamespace.Get("http://schemas.microsoft.com/SystemCenter/Common/UI/Views/GridView");
    var expressions = (from ds in doc.Root.Descendants(ns + "Column")
                       select ds).ToList();
    ViewPresentation vp = new ViewPresentation();
    List<ViewPresentation> listColumns = new List<ViewPresentation>();

    for (int i = 0; i < expressions.Count; i++)
    {
        ViewPresentation VP = new ViewPresentation();

        var xml = XElement.Parse(expressions[i].ToString());

        vp.columName = xml.Attribute("Name").Value;
        vp.displayName = xml.Attribute("DisplayName").Value;
        vp.memberBinding = xml.Attribute("DisplayMemberBinding").Value;
        vp.property = xml.Attribute("Property").Value;
        vp.dataType = xml.Attribute("DataType").Value;

        listColumns.Add(vp);
    }
    return listColumns;
}

我通过web服务调用此方法并返回对象,但它只显示列表中的最后一项,即使我通过dll的代码调试它正在填写任何我认为Web服务方法的想法这样

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string  GetColumnsFromViews()
{
    string itemSource, critera;
    Parser viewsParserObject = new Parser();
    viewsParserObject.xmlfilename = @"C:\Development\Source\Portal\SVNMostRecent\Portal\CustomView.xml";
    itemSource= viewsParserObject.LoadFromXml();
    critera = viewsParserObject.GetCriteraFromXmlFile("/Data");
    List<ViewPresentation> mycolumns = viewsParserObject.GetColumnsFromXml(critera, "/Data");
    System.Web.Script.Serialization.JavaScriptSerializer jSearializer = new System.Web.Script.Serialization.JavaScriptSerializer();
    return jSearializer.Serialize(mycolumns);
}

返回的值如下:

<string xmlns="http://tempuri.org/">
[
    {
        "id": -1,
        "viewName": "",
        "columName": "{Binding Path=Impact.DisplayName, Mode=OneWay}",
        "memberBinding": "{Binding Path=Impact.DisplayName, Mode=OneWay}",
        "displayName": "Impact.f412c72e91104455b1695ef1ccca4e91",
        "property": "Impact.DisplayName",
        "dataType": "s:String",
        "ViewStrings": []
    },
    {
        "id": -1,
        "viewName": "",
        "columName": "{Binding Path=Impact.DisplayName, Mode=OneWay}",
        "memberBinding": "{Binding Path=Impact.DisplayName, Mode=OneWay}",
        "displayName": "Impact.f412c72e91104455b1695ef1ccca4e91",
        "property": "Impact.DisplayName",
        "dataType": "s:String",
        "ViewStrings": []
    },
    {
        "id": -1,
        "viewName": "",
        "columName": "{Binding Path=Impact.DisplayName, Mode=OneWay}",
        "memberBinding": "{Binding Path=Impact.DisplayName, Mode=OneWay}",
        "displayName": "Impact.f412c72e91104455b1695ef1ccca4e91",
        "property": "Impact.DisplayName",
        "dataType": "s:String",
        "ViewStrings": []
    },
    {
        "id": -1,
        "viewName": "",
        "columName": "{Binding Path=Impact.DisplayName, Mode=OneWay}",
        "memberBinding": "{Binding Path=Impact.DisplayName, Mode=OneWay}",
        "displayName": "Impact.f412c72e91104455b1695ef1ccca4e91",
        "property": "Impact.DisplayName",
        "dataType": "s:String",
        "ViewStrings": []
    },
    {
        "id": -1,
        "viewName": "",
        "columName": "{Binding Path=Impact.DisplayName, Mode=OneWay}",
        "memberBinding": "{Binding Path=Impact.DisplayName, Mode=OneWay}",
        "displayName": "Impact.f412c72e91104455b1695ef1ccca4e91",
        "property": "Impact.DisplayName",
        "dataType": "s:String",
        "ViewStrings": []
    },
    {
        "id": -1,
        "viewName": "",
        "columName": "{Binding Path=Impact.DisplayName, Mode=OneWay}",
        "memberBinding": "{Binding Path=Impact.DisplayName, Mode=OneWay}",
        "displayName": "Impact.f412c72e91104455b1695ef1ccca4e91",
        "property": "Impact.DisplayName",
        "dataType": "s:String",
        "ViewStrings": []
    },
    {
        "id": -1,
        "viewName": "",
        "columName": "{Binding Path=Impact.DisplayName, Mode=OneWay}",
        "memberBinding": "{Binding Path=Impact.DisplayName, Mode=OneWay}",
        "displayName": "Impact.f412c72e91104455b1695ef1ccca4e91",
        "property": "Impact.DisplayName",
        "dataType": "s:String",
        "ViewStrings": []
    },
    {
        "id": -1,
        "viewName": "",
        "columName": "{Binding Path=Impact.DisplayName, Mode=OneWay}",
        "memberBinding": "{Binding Path=Impact.DisplayName, Mode=OneWay}",
        "displayName": "Impact.f412c72e91104455b1695ef1ccca4e91",
        "property": "Impact.DisplayName",
        "dataType": "s:String",
        "ViewStrings": []
    },
    {
        "id": -1,
        "viewName": "",
        "columName": "{Binding Path=Impact.DisplayName, Mode=OneWay}",
        "memberBinding": "{Binding Path=Impact.DisplayName, Mode=OneWay}",
        "displayName": "Impact.f412c72e91104455b1695ef1ccca4e91",
        "property": "Impact.DisplayName",
        "dataType": "s:String",
        "ViewStrings": []
    }
]
</string> 

Xml来源

<?xml version="1.0" encoding="utf-8" ?>
<Data>
  <View>
    <Adapters>
      <Adapter AdapterName="dataportal:EnterpriseManagementObjectAdapter">
        <AdapterAssembly>Microsoft.EnterpriseManagement.UI.SdkDataAccess</AdapterAssembly>
        <AdapterType>Microsoft.EnterpriseManagement.UI.SdkDataAccess.DataAdapters.EnterpriseManagementObjectAdapter</AdapterType>
      </Adapter>
      <Adapter AdapterName="viewframework://Adapters/AdvancedList">
        <AdapterAssembly>Microsoft.EnterpriseManagement.UI.ViewFramework</AdapterAssembly>
        <AdapterType>Microsoft.EnterpriseManagement.UI.ViewFramework.AdvancedListSupportAdapter</AdapterType>
      </Adapter>
      <Adapter AdapterName="omsdk://Adapters/Criteria">
        <AdapterAssembly>Microsoft.EnterpriseManagement.UI.SdkDataAccess</AdapterAssembly>
        <AdapterType>Microsoft.EnterpriseManagement.UI.SdkDataAccess.DataAdapters.SdkCriteriaAdapter</AdapterType>
      </Adapter>
    </Adapters>
    <ItemsSource>
      <AdvancedListSupportClass DataTypeName="" AdapterName="viewframework://Adapters/AdvancedList" FullUpdateAdapter="dataportal:EnterpriseManagementObjectAdapter" DataSource="mom:ManagementGroup" FullUpdateFrequency="1" Streaming="true" IsRecurring="true" RecurrenceFrequency="{x:Static s:Int32.MaxValue}" xmlns="clr-namespace:Microsoft.EnterpriseManagement.UI.ViewFramework;assembly=Microsoft.EnterpriseManagement.UI.ViewFramework" xmlns:av="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib">
        <AdvancedListSupportClass.Parameters>
          <QueryParameter Parameter="ManagementPackClassId" Value="$MPElement[Name='CoreIncident!System.WorkItem.Incident']$" />
        </AdvancedListSupportClass.Parameters>
      </AdvancedListSupportClass>
    </ItemsSource>
    <Criteria />
    <Presentation>
      <Columns>
        <mux:ColumnCollection xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:mux="http://schemas.microsoft.com/SystemCenter/Common/UI/Views/GridView" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:datebinding="clr-namespace:Microsoft.EnterpriseManagement.UI.Extensions;assembly=Microsoft.EnterpriseManagement.UI.Extensions" xmlns:data="clr-namespace:Microsoft.EnterpriseManagement.UI.Extensions;assembly=Microsoft.EnterpriseManagement.UI.Extensions" xmlns:appCommon="clr-namespace:Microsoft.EnterpriseManagement.ServiceManager.Application.Common;assembly=Microsoft.EnterpriseManagement.ServiceManager.Application.Common" xmlns:toolbox="clr-namespace:Microsoft.EnterpriseManagement.UI.WpfToolbox;assembly=Microsoft.EnterpriseManagement.UI.FormsInfra" xmlns:slaBinding="clr-namespace:Microsoft.EnterpriseManagement.ServiceManager.SLA.Common;assembly=Microsoft.EnterpriseManagement.ServiceManager.SLA.Common">
          <mux:Column Name="ActualCost" DisplayMemberBinding="{Binding Path=ActualCost, Mode=OneWay}" Width="100" DisplayName="ActualCost.c8e7234bdd574f8097fd3b0d7fb35851" Property="ActualCost" DataType="s:Double" />
          <mux:Column Name="ActualDowntimeEndDate" DisplayMemberBinding="{datebinding:DateBinding Path=ActualDowntimeEndDate, Mode=OneWay}" Width="100" DisplayName="ActualDowntimeEndDate.ed1a5af04f814341a88766f2fa18c447" Property="ActualDowntimeEndDate" DataType="s:DateTime" />
          <mux:Column Name="ActualDowntimeStartDate" DisplayMemberBinding="{datebinding:DateBinding Path=ActualDowntimeStartDate, Mode=OneWay}" Width="100" DisplayName="ActualDowntimeStartDate.34daa34691ed435597c3a230ff5d8c60" Property="ActualDowntimeStartDate" DataType="s:DateTime" />
          <mux:Column Name="ActualWork" DisplayMemberBinding="{Binding Path=ActualWork, Mode=OneWay}" Width="100" DisplayName="ActualWork.4afb1225100040ef8cf93871389b3380" Property="ActualWork" DataType="s:Double" />
          <mux:Column Name="Description" DisplayMemberBinding="{Binding Path=Description, Mode=OneWay}" Width="100" DisplayName="Description.f461792cf5d64b10aae47e4c980792e4" Property="Description" DataType="s:String" />
          <mux:Column Name="DisplayName" DisplayMemberBinding="{Binding Path=DisplayName, Mode=OneWay}" Width="100" DisplayName="DisplayName.ef4712b1ecbf4f4d9dcea38daa28269e" Property="DisplayName" DataType="s:String" />
          <mux:Column Name="$DisplayName$" DisplayMemberBinding="{Binding Path=$DisplayName$, Mode=OneWay}" Width="100" DisplayName="DisplayName.99931bcb16c142cb944c3c2e43467548" Property="$DisplayName$" DataType="s:String" />
          <mux:Column Name="$FullName$" DisplayMemberBinding="{Binding Path=$FullName$, Mode=OneWay}" Width="100" DisplayName="FullName.a1b287d94ab04324857568c878defda9" Property="$FullName$" DataType="s:String" />
          <mux:Column Name="Impact.DisplayName" DisplayMemberBinding="{Binding Path=Impact.DisplayName, Mode=OneWay}" Width="100" DisplayName="Impact.f412c72e91104455b1695ef1ccca4e91" Property="Impact.DisplayName" DataType="s:String" />
        </mux:ColumnCollection>
      </Columns>
      <AdditonalProperties />
      <ViewStrings>
        <ViewString ID="ActualCost.c8e7234bdd574f8097fd3b0d7fb35851">$MPElement[Name="ActualCost.c8e7234bdd574f8097fd3b0d7fb35851"]$</ViewString>
        <ViewString ID="ActualDowntimeEndDate.ed1a5af04f814341a88766f2fa18c447">$MPElement[Name="ActualDowntimeEndDate.ed1a5af04f814341a88766f2fa18c447"]$</ViewString>
        <ViewString ID="ActualDowntimeStartDate.34daa34691ed435597c3a230ff5d8c60">$MPElement[Name="ActualDowntimeStartDate.34daa34691ed435597c3a230ff5d8c60"]$</ViewString>
        <ViewString ID="ActualWork.4afb1225100040ef8cf93871389b3380">$MPElement[Name="ActualWork.4afb1225100040ef8cf93871389b3380"]$</ViewString>
        <ViewString ID="Description.f461792cf5d64b10aae47e4c980792e4">$MPElement[Name="Description.f461792cf5d64b10aae47e4c980792e4"]$</ViewString>
        <ViewString ID="DisplayName.ef4712b1ecbf4f4d9dcea38daa28269e">$MPElement[Name="DisplayName.ef4712b1ecbf4f4d9dcea38daa28269e"]$</ViewString>
        <ViewString ID="DisplayName.99931bcb16c142cb944c3c2e43467548">$MPElement[Name="DisplayName.99931bcb16c142cb944c3c2e43467548"]$</ViewString>
        <ViewString ID="FullName.a1b287d94ab04324857568c878defda9">$MPElement[Name="FullName.a1b287d94ab04324857568c878defda9"]$</ViewString>
        <ViewString ID="Impact.f412c72e91104455b1695ef1ccca4e91">$MPElement[Name="Impact.f412c72e91104455b1695ef1ccca4e91"]$</ViewString>
      </ViewStrings>
    </Presentation>
  </View>
</Data>

0 个答案:

没有答案