此反序列化XML是字符串:故障在.NET
string incomingOrdreXML = @"<GetOrderStatus xmlns:i=""http://www.w3.org/2001/XMLSchema-instance"" xmlns=""http://schemas.datacontract.org/2004/07/OrderStatusConsole""><AccountID>5</AccountID><Batch></Batch><Date></Date><OrderNumber></OrderNumber><Password></Password><Sequence></Sequence><StatusCode></StatusCode><Test></Test><TrackingID></TrackingID></GetOrderStatus>";
這是類:
public class GetOrderStatus
{
public string AccountID { get; set; }
public string Password { get; set; }
public string Batch { get; set; }
public string Sequence { get; set; }
public string Test { get; set; }
public string Date { get; set; }
public string OrderNumber { get; set; }
public string StatusCode { get; set; }
public string TrackingID { get; set; }
}
這是反串行化代碼:
string incomingOrdreXML = @"<GetOrderStatus xmlns:i=""http://www.w3.org/2001/XMLSchema-instance"" xmlns=""http://schemas.datacontract.org/2004/07/OrderStatusConsole""><AccountID>5</AccountID><Batch></Batch><Date></Date><OrderNumber></OrderNumber><Password></Password><Sequence></Sequence><StatusCode></StatusCode><Test></Test><TrackingID></TrackingID></GetOrderStatus>";
var reader = new StringReader(incomingOrdreXML);
XmlSerializer serializer = new XmlSerializer(typeof(GetOrderStatus));
var instance = (GetOrderStatus)serializer.Deserialize(reader);
失敗在最後一行,說
{"<GetOrderStatus xmlns='http://schemas.datacontract.org/2004/07/OrderStatusConsole'> was not expected."}
這條線將根據誰發送這個XML而改變。這意味着如果發件人是OrderStatusConsole,那麼如果發件人是Jeff,那麼它就像上面那樣,那麼它最終會有Jeff。
任何線索?
在此先感謝。