English 中文(简体)
c# 数据周期
原标题:c# DataContractSerializer issue
  • 时间:2012-01-13 15:32:13
  •  标签:
  • c#
  • wpf
  • wcf

I m 从恢复XML的有偿服务中提取数据

<CollectionOfItems>
  <Item>
    <Param1>param1 value</Param1>
    <Param2>param2 value</Param2>
  </Item>
  <Item>
    <Param1>param1 value</Param1>
    <Param2>param2 value</Param2>  
  </Item>
</CollectionOfItems>

采用“方法一米”来消费其他服务

public object getMetaData(string uri, Type type)
    {
        //Create Object To Be Returned
        object result = null;
        //Create Web Request
        HttpWebRequest request = WebRequest.Create(uri) as HttpWebRequest;
        //Get Response
        using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
        {
            if (request.HaveResponse && response != null)
            {
                using (Stream reader = response.GetResponseStream())
                {
                    DataContractSerializer xmlSer = new DataContractSerializer(type);

                    result = xmlSer.ReadObject(reader);
                }
            }
        }
        return result;
    }

我有一个与<代码><CollectionOfItems>相匹配的班子。

[CollectionDataContract(Name = "CollectionOfItems", Namespace = "http://matchingnamespace")]
    public class CollectionOfItems: List<Item>
    {
    }

持有<代码><Item>

[DataContract(Name="Item")]
    public class Item
    {
        [DataMember(Name="Param1")]
        public string param1{ get; set; }

        [DataMember(Name="Param2")]
        public string param2{ get; set; }
    }

我的问题是,当我把结果归结为名单方框一时,最后有一个目标,即有正确的成果,但我只把结果视为空白。 我似乎有<条码>和t;CollectionOfItems>,其正确数额为<Item>,但我看不出第1款或第2款等值。

最佳回答

一位朋友刚刚为我解决了这一问题。 这里要回答有类似问题的人。 如果在收集数据合同中存在名称空间,则必须在项目数据合同中公布。 页: 1

[DataContract(Name="Item", Namespace = "http://matchingnamespace")] 
    public class Item 
    { 
        [DataMember(Name="Param1")] 
        public string param1{ get; set; } 

        [DataMember(Name="Param2")] 
        public string param2{ get; set; } 
    } 
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签