我試圖反序列化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