我有一個時間的惡魔從Web服務中獲得一些簡單的xml以正確反序列化。當我實際反序列化時,沒有任何錯誤,但是最終的對象只能進行深度嵌套 - 一旦到達「返回」標記,它和所有的子元素都是空的。我似乎無法弄清楚爲什麼它在這一點上是失敗的......它似乎與其他類相同。有誰知道什麼是錯的?SOAP XML只能部分反序列化
示例XML響應:
<?xml version="1.0" encoding="UTF-8"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getPreSubmitInfoResponse xmlns:ns2="http://webservice.integration.someservice.com/">
<return>
<errorOccurred>false</errorOccurred>
<message>Information returned successfully</message>
<response xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:webServicePO">
<internalMessage>SUCCESS: Inventory Found</internalMessage>
<poNum>56658</poNum>
<residence>N</residence>
<shipAddress1>TEST</shipAddress1>
<shipAddress2 />
<shipCity>TEST</shipCity>
<shipMethod>UPS</shipMethod>
<shipState>TX</shipState>
<shipTo>TEST'S</shipTo>
<shipZip>99999</shipZip>
<webServicePoDetailList>
<color>TEST</color>
<errorOccured>false</errorOccured>
<inventoryKey>TEST</inventoryKey>
<message>Requested Quantity is confirmed and available in warehouse '2' to ship to your destination.</message>
<quantity>5</quantity>
<size>XS</size>
<sizeIndex>1</sizeIndex>
<style>TEST</style>
<whseNo>2</whseNo>
</webServicePoDetailList>
</response>
</return>
</ns2:getPreSubmitInfoResponse>
C#類:
[XmlRoot(ElementName = "webServicePoDetailList")]
public class WebServicePoDetailList
{
[XmlAttribute(AttributeName = "color")]
public string Color { get; set; }
[XmlAttribute(AttributeName = "errorOccured")]
public string ErrorOccured { get; set; }
[XmlAttribute(AttributeName = "inventoryKey")]
public string InventoryKey { get; set; }
[XmlAttribute(AttributeName = "message")]
public string Message { get; set; }
[XmlAttribute(AttributeName = "quantity")]
public string Quantity { get; set; }
[XmlAttribute(AttributeName = "size")]
public string Size { get; set; }
[XmlAttribute(AttributeName = "sizeIndex")]
public string SizeIndex { get; set; }
[XmlAttribute(AttributeName = "style")]
public string Style { get; set; }
[XmlAttribute(AttributeName = "whseNo")]
public string WhseNo { get; set; }
}
[XmlRoot(ElementName = "response")]
//[XmlInclude(typeof(webServicePO))]
public class Response
{
[XmlAttribute(AttributeName = "internalMessage")]
public string InternalMessage { get; set; }
[XmlAttribute(AttributeName = "poNum")]
public string PoNum { get; set; }
[XmlAttribute(AttributeName = "residence")]
public string Residence { get; set; }
[XmlAttribute(AttributeName = "shipAddress1")]
public string ShipAddress1 { get; set; }
[XmlAttribute(AttributeName = "shipAddress2")]
public string ShipAddress2 { get; set; }
[XmlAttribute(AttributeName = "shipCity")]
public string ShipCity { get; set; }
[XmlAttribute(AttributeName = "shipMethod")]
public string ShipMethod { get; set; }
[XmlAttribute(AttributeName = "shipState")]
public string ShipState { get; set; }
[XmlAttribute(AttributeName = "shipTo")]
public string ShipTo { get; set; }
[XmlAttribute(AttributeName = "shipZip")]
public string ShipZip { get; set; }
[XmlElement(ElementName = "webServicePoDetailList")]
public WebServicePoDetailList WebServicePoDetailList { get; set; }
}
//[Serializable()]
//[XmlRoot(Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
//public class webServicePO : Response { }
[XmlRoot(ElementName = "return")]
public class Return
{
[XmlAttribute(AttributeName = "errorOccurred")]
public string ErrorOccurred { get; set; }
[XmlAttribute(AttributeName = "message")]
public string Message { get; set; }
[XmlElement(ElementName = "response")]
public Response Response { get; set; }
}
[XmlRoot(ElementName = "getPreSubmitInfoResponse", Namespace = "http://webservice.integration.someservice.com/")]
public class GetPreSubmitInfoResponse
{
[XmlElement(ElementName = "return")]
public Return Return { get; set; }
}
[XmlRoot(ElementName = "Body")]
public class Body
{
[XmlElement(ElementName = "getPreSubmitInfoResponse", Namespace = "http://webservice.integration.someservice.com/")]
public GetPreSubmitInfoResponse GetPreSubmitInfoResponse { get; set; }
}
[XmlRoot(ElementName = "Envelope", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
public class Envelope
{
[XmlElement(ElementName = "Body")]
public Body Body { get; set; }
}
你會發現,我試圖適應XSI:響應中類型=聲明,但沒有成功。我也嘗試用replace方法刪除該聲明,但沒有任何工作。當我最初將此響應轉換爲C#類時,所有字符串都被定義爲元素,而不是屬性,我認爲這是不正確的。我改變了他們,請讓我知道如果這是一個錯誤(兩種方法都行不通)。我也玩過響應命名空間,但我不確定這與我當前的錯誤有什麼關係,因爲鏈中的第一個空對象是「返回」。
即使對某個問題可能存在的位置有所瞭解也會有所幫助。如果「返回」爲空,那麼這是否意味着問題出現在「返回」類中或者它可能是其中的一個孩子? –