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款等值。