我有一个问题的问题xml响应
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));
}
}
}
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("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://www.ibm.com/xmlns/db2/cm/beans/1.0/schema")]
public partial class Item : object, System.ComponentModel.INotifyPropertyChanged {
private System.Xml.XmlElement itemXMLField;
private string uRIField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Order=0)]
public System.Xml.XmlElement ItemXML {
get {
return this.itemXMLField;
}
set {
this.itemXMLField = value;
this.RaisePropertyChanged("ItemXML");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string URI {
get {
return this.uRIField;
}
set {
this.uRIField = value;
this.RaisePropertyChanged("URI");
}
}
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));
}
}
}
您不是在告诉serialiser默认名称空间是什么。
尝试以下操作:
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);
看起来您还没有将文档加载到文档中。
var doc = ?????
doc.Load(???xmlfile???);
var response = doc.Descendants().Where(x => x.Name.LocalName == typeof(RunQueryReply).Name).FirstOrDefault();
(RunQueryReply)s.Deserialize(response.CreateReader());