C# 反序列化对象C中的响应#
我对反序列化xml响应有问题C# 反序列化对象C中的响应#,c#,xml,web-services,C#,Xml,Web Services,我对反序列化xml响应有问题 string soapResult; using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult)) { using (StreamReader rd = new StreamReader(webResponse.GetResponseStream())) { soapResult = rd.ReadToEnd(); } return
string soapResult;
using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult))
{
using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
{
soapResult = rd.ReadToEnd();
}
return soapResult;
}
var dd=CallWebService("cmfs:9115/CMBSpecificWebService/services/…");
var doc = XDocument.Parse(dd);
XmlSerializer s = new XmlSerializer(typeof(RunQueryReply));
var response = doc.Descendants().Where(x => x.Name.LocalName == typeof(RunQueryReply).Name).FirstOrDefault();
(RunQueryReply)s.Deserialize(response.CreateReader());
System.Xml.dll中发生类型为“System.InvalidOperationException”的未处理异常
其他信息:XML文档(0,0)中存在错误
答复:<ns1:RunQueryReply xmlns="http://www.ibm.com/xmlns/db2/cm/beans/1.0/schema" xmlns:ns1="http://www.ibm.com/xmlns/db2/cm/beans/1.0/schema">
<ns1:RequestStatus success="true"></ns1:RequestStatus>
<ns1:ResultSet count="5">
<ns1:Item URI="http://test:9115/TestWebService/CMBGetPIDUrl?pid=93 3 ICM6 i2mnlsdd13 RB_ClientN59 26 A1001001A16K02B12842F0117018 A16K02B12842F011702 14 2680&server=icmnlsdb&dsType=ICM">
<ns1:ItemXML />
</ns1:Item>
<ns1:Item URI="http://test:9115/TestWebService/CMBGetPIDUrl?pid=93 3 ICM6 i2mnlsdd13 RB_ClientN59 26 A1001001A16K02B41832H0124418 A16K02B41832H012442 12 2680&server=icmnlsdb&dsType=ICM">
<ns1:ItemXML />
</ns1:Item>
<ns1:Item URI="http://test:9115/TestWebService/CMBGetPIDUrl?pid=93 3 ICM6 i2mnlsdd13 RB_ClientN59 26 A1001001A16K02B42003D0124618 A16K02B42003D012431 12 2680&server=icmnlsdb&dsType=ICM">
<ns1:ItemXML />
</ns1:Item>
<ns1:Item URI="http://test:9115/TestWebService/CMBGetPIDUrl?pid=93 3 ICM6 i2mnlsdd13 RB_ClientN59 26 A1001001A16K11B11808G3379311 A16K11B11808G337431 12 2680&server=icmnlsdb&dsType=ICM">
<ns1:ItemXML />
</ns1:Item>
<ns1:Item URI="http://test:9115/TestWebService/CMBGetPIDUrl?pid=93 3 ICM6 i2mnlsdb13 RB_ClientN59 26 A1001001A17A25B11425B0804018 A17A25B11425B082401 11 2680&server=icmnlsdb&dsType=ICM">
<ns1:ItemXML />
</ns1:Item>
</ns1:ResultSet>
</ns1:RunQueryReply>
RunQueryReply:
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.6.1055.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://www.ibm.com/xmlns/db2/cm/beans/1.0/schema")]
public partial class RunQueryReply : object, System.ComponentModel.INotifyPropertyChanged {
private RequestStatus requestStatusField;
private RunQueryReplyResultSet resultSetField;
private MTOMAttachment[] mtomRefField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Order=0)]
public RequestStatus RequestStatus {
get {
return this.requestStatusField;
}
set {
this.requestStatusField = value;
this.RaisePropertyChanged("RequestStatus");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Order=1)]
public RunQueryReplyResultSet ResultSet {
get {
return this.resultSetField;
}
set {
this.resultSetField = value;
this.RaisePropertyChanged("ResultSet");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("mtomRef", Order=2)]
public MTOMAttachment[] mtomRef {
get {
return this.mtomRefField;
}
set {
this.mtomRefField = value;
this.RaisePropertyChanged("mtomRef");
}
}
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName) {
System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if ((propertyChanged != null)) {
propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute(“System.Xml”,“4.6.1055.0”)]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute(“代码”)]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true,命名空间=”http://www.ibm.com/xmlns/db2/cm/beans/1.0/schema")]
公共分部类RunQueryReply:对象,System.ComponentModel.INotifyPropertyChanged{
private RequestStatus RequestStatus字段;
私有RunQueryReplyResultSet resultSetField;
私有MTOMAttachment[]mtomRefField;
///
[System.Xml.Serialization.XmlElementAttribute(顺序=0)]
公共请求状态请求状态{
得到{
返回此.RequestStatus字段;
}
设置{
this.requestStatusField=值;
此.RaisePropertyChanged(“请求状态”);
}
}
///
[System.Xml.Serialization.XmlElementAttribute(顺序=1)]
公共RunQueryReplyResultSet结果集{
得到{
返回this.resultSetField;
}
设置{
this.resultSetField=值;
此.RaisePropertyChanged(“结果集”);
}
}
///
[System.Xml.Serialization.xmlementAttribute(“mtomRef”,Order=2)]
公共MTOMAttachment[]mtomRef{
得到{
返回this.mtomRefField;
}
设置{
this.mtomRefField=值;
本.RaisePropertyChanged(“mtomRef”);
}
}
公共事件System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
受保护的void RaisePropertyChanged(字符串propertyName){
System.ComponentModel.PropertyChangedEventHandler propertyChanged=this.propertyChanged;
如果((propertyChanged!=null)){
propertyChanged(这是新的System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}
RunQueryResultSet:
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.6.1055.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://www.ibm.com/xmlns/db2/cm/beans/1.0/schema")]
public partial class RunQueryReplyResultSet : object, System.ComponentModel.INotifyPropertyChanged {
private Item[] itemField;
private int countField;
public RunQueryReplyResultSet() {
this.countField = 0;
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("Item", Order=0)]
public Item[] Item {
get {
return this.itemField;
}
set {
this.itemField = value;
this.RaisePropertyChanged("Item");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
[System.ComponentModel.DefaultValueAttribute(0)]
public int count {
get {
return this.countField;
}
set {
this.countField = value;
this.RaisePropertyChanged("count");
}
}
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName) {
System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if ((propertyChanged != null)) {
propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute(“System.Xml”,“4.6.1055.0”)]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute(“代码”)]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true,命名空间=”http://www.ibm.com/xmlns/db2/cm/beans/1.0/schema")]
公共部分类RunQueryReplyResultSet:对象,System.ComponentModel.INotifyPropertyChanged{
私有项[]项字段;
私有int countField;
公共RunQueryReplyResultSet(){
this.countField=0;
}
///
[System.Xml.Serialization.XmlElementAttribute(“项”,顺序=0)]
公共项目[]项目{
得到{
返回此.itemField;
}
设置{
this.itemField=值;
本.增加财产变更(“项目”);
}
}
///
[System.Xml.Serialization.XmlAttributeAttribute()]
[System.ComponentModel.DefaultValueAttribute(0)]
公共整数计数{
得到{
返回此.countField;
}
设置{
this.countField=值;
本.增加财产变更(“计数”);
}
}
公共事件System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
受保护的void RaisePropertyChanged(字符串propertyName){
System.ComponentModel.PropertyChangedEventHandler propertyChanged=this.propertyChanged;
如果((propertyChanged!=null)){
propertyChanged(这是新的System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}
项目:
[System.CodeDom.Compiler.GeneratedCodeAttribute(“System.Xml”,“4.6.1055.0”)]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute(“代码”)]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true,命名空间=”http://www.ibm.com/xmlns/db2/cm/beans/1.0/schema")]
公共部分类项:对象,System.ComponentModel.INotifyPropertyChanged{
private System.Xml.xmlement itemXMLField;
私有字符串字段;
///
[System.Xml.Serialization.XmlElementAttribute(顺序=0)]
public System.Xml.xmlement ItemXML{
得到{
返回此.itemXMLField;
}
设置{
this.itemXMLField=值;
this.RaisePropertyChanged(“ItemXML”);
}
}
///
[System.Xml.Serialization.XmlAttributeAttribute()]
公共字符串URI{
得到{
返回这个.uRIField;
}
设置{
this.uRIField=值;
此.RaisePropertyChanged(“URI”);
}
}
公共事件System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
受保护的void RaisePropertyChanged(字符串propertyName){
System.ComponentModel.PropertyChangedEventHandler propertyChanged=this.propertyChanged;
如果((propertyChanged!=null)){
propertyChanged(这是新的System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}
看起来您尚未将文档加载到文档中
var doc = ?????
doc.Load(???xmlfile???);
var response = doc.Descendants().Where(x => x.Name.LocalName == typeof(RunQueryReply).Name).FirstOrDefault();
(RunQueryReply)s.Deserialize(response.CreateReader());
<
var doc = ?????
doc.Load(???xmlfile???);
var response = doc.Descendants().Where(x => x.Name.LocalName == typeof(RunQueryReply).Name).FirstOrDefault();
(RunQueryReply)s.Deserialize(response.CreateReader());
var stream = new StringReader(dd);
XmlSerializer s = new XmlSerializer(typeof(RunQueryReply), "http://www.ibm.com/xmlns/db2/cm/beans/1.0/schema");
var a = (RunQueryReply) s.Deserialize(stream);