我试图反序列化SOAP响应。
SOAP响应是这样的:反序列化SOAP响应中的对象
<soapenv:Body>
<mp0:MP0123_ConnectorRequest_001_Result>
<!--You have a CHOICE of the next 2 items at this level-->
<mp0:result success="true">
<!--1 or more repetitions:-->
<mp0:actionResult type="?" aid="?">
<mp0:success>?</mp0:success>
<!--Optional:-->
<mp0:errorMessage>?</mp0:errorMessage>
<!--Zero or more repetitions:-->
<mp0:dataResult>
<!--1 or more repetitions:-->
<mp0:datafield>
<bas:name>?</bas:name>
<bas:value null="false" encoding="none">?</bas:value>
</mp0:datafield>
</mp0:dataResult>
</mp0:actionResult>
</mp0:result>
<mp0:result-in-file>
<bas:ticket>?</bas:ticket>
<bas:members>
<!--You have a CHOICE of the next 2 items at this level-->
<bas:sequence min="?" max="?"/>
<bas:lables>
<!--1 or more repetitions:-->
<bas:fr-label aid="?">?</bas:fr-label>
</bas:lables>
</bas:members>
</mp0:result-in-file>
</mp0:MP0123_ConnectorRequest_001_Result>
</soapenv:Body>
从WSDL生成的类是这样的:
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34234")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://schemas.datastream.net/MP_results/MP0123_001")]
public partial class MP0123_ConnectorRequest_001_Result {
private object itemField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("result", typeof(MP0123_ConnectorRequest_001_ResultResult))]
[System.Xml.Serialization.XmlElementAttribute("result-in-file", typeof(fileResult))]
public object Item {
get {
return this.itemField;
}
set {
this.itemField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34234")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://schemas.datastream.net/MP_results/MP0123_001")]
public partial class MP0123_ConnectorRequest_001_ResultResult {
private MP0123_ConnectorRequest_001_ResultResultActionResult[] actionResultField;
private bool successField;
public MP0123_ConnectorRequest_001_ResultResult() {
this.successField = true;
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("actionResult")]
public MP0123_ConnectorRequest_001_ResultResultActionResult[] actionResult {
get {
return this.actionResultField;
}
set {
this.actionResultField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
[System.ComponentModel.DefaultValueAttribute(true)]
public bool success {
get {
return this.successField;
}
set {
this.successField = value;
}
}
}
现在,我得到了下面的代码的响应,但是作为唯一的事情是Response.Item,它是我无法反序列化的对象。
var response = connector.ConnectorRequestOp(Request);
var serializer = new XmlSerializer(typeof(ConnectorRequest_001_ResultResult),"http://schemas.datastream.net/MP_results/MP0123_001");
var responseREsult = (MP0123_ConnectorRequest_001_ResultResult)serializer.Deserialize(new MemoryStream(response.Item));
我知道,我不能在这种情况下使用MemoryStream
,所以我搜索了很多,在这里读到类似的职位,但唯一可行的办法,我发现是使用的路径和使用FileStream
,但我不知道有反应路径(我认为)。那么是否有任何方法来反序列化一个对象?
我不知道是否我错过了序列化/反序列化肥皂响应中的一些重要概念,因为这是我第一次处理这个问题。
感谢
你并不需要手动反序列化,只需要使用生成的代理类。 – 2014-11-21 17:00:29
你的意思是把它作为班级,就是这样吗? – 2014-11-21 17:06:00
只需调用你的方法。他们会返回适当的对象。 – 2014-11-21 17:26:49