XML을 C# 객체로 비 직렬화하려고합니다. 내 클래스가 그대로객체에 직렬화 해제
<StaffingOrder xmlns='StaffinfOrderNamespace' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<OrderId idOwner="VMSAccess">
<IdValue name='RequisitionID'>1</IdValue>
<IdValue name='KellyBranch'>3319</IdValue>
</OrderId>
</StaffingOrder>
:
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
[XmlRoot("StaffingOrder")]
public class OrderId
{
[XmlElement(ElementName = "RequisitionID")]
public int RequisitionID { get; set; }
[XmlElement(ElementName = "KellyBranch")]
public int KellyBranch { get; set; }
}
내 WCF 서비스 계약을있는 그대로 : 나는 같은 역 직렬화하려고
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "UploadOrderDocument",
RequestFormat = WebMessageFormat.Xml,
ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Bare)]
[XmlSerializerFormat]
OrderId UploadOrderDocument(string hrXML);
:로
내 XML은
public OrderId UploadOrderDocument(string hrXMLString)
{
OrderId orderId = new OrderId();
using (StringReader sr = new StringReader(hrXMLString))
{
XmlSerializer xs = new XmlSerializer(typeof(OrderId));
orderId = (OrderId)xs.Deserialize(sr);
var temp = orderId.RequisitionID;
}
return orderId;
}
deserialize하는 동안 오류가 발생하지 않지만 RequisitionID
값을 가져 오지 못합니다.
여러 요소 속성이있는 XML 파일의 비 직렬화 - 특성이 비 직렬화되지 않음] (http://stackoverflow.com/questions/14245846/deserializing-xml-file-with-multiple-element-attributes-attributes-are) -not-des) – niksofteng