Can't marshall WebAPI XML response into C# object

Slavaa

New Member
I have some XML coming back from a REST service that I am having trouble marshalling to a C# class. The XML looks like this:\[code\]<?xml version="1.0" encoding="UTF-8" standalone="yes"?><SCResponse> <link href="http://192.168.6.126:8001/affiliate/account/81/notifications?startRow=2&limit=20" rel="next_page" title="Next"/> <link href="http://192.168.6.126:8001/affiliate/account/81/notifications?startRow=1&limit=20" rel="previous_page" title="Previous"/> <RecordLimit>20</RecordLimit> <Notifications> <Notification href="http://192.168.6.126:8001/affiliate/account/81/notifications/24"> <NotificationDate>2013-03-15T16:41:37-05:00</NotificationDate> <NotificationDetails>Notification details 1</NotificationDetails> <Status>New</Status> <NotificationTitle>Test notification 1</NotificationTitle> </Notification> </Notifications> <RecordsReturned>1</RecordsReturned> <StartingRecord>1</StartingRecord> <TotalRecords>1</TotalRecords></SCResponse>\[/code\]and the class that was automatically generated by 'Paste as Special' looks like this:\[code\]using System;using System.Collections.Generic;using System.Linq;using System.Runtime.Serialization;using System.Web;using System.Xml.Serialization;namespace CMINet.Models.notifications{/// <remarks/>[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)][System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]// to make it work I must replace the above with:// [XmlType]// [DataContract(Namespace = "")]public partial class SCResponse{ private SCResponseLink[] linkField; private byte recordLimitField; private SCResponseNotifications notificationsField; private byte recordsReturnedField; private byte startingRecordField; private byte totalRecordsField; /// <remarks/> [System.Xml.Serialization.XmlElementAttribute("link")] public SCResponseLink[] link { get { return this.linkField; } set { this.linkField = value; } } /// <remarks/> public byte RecordLimit { get { return this.recordLimitField; } set { this.recordLimitField = value; } } /// <remarks/> public SCResponseNotifications Notifications { get { return this.notificationsField; } set { this.notificationsField = value; } } /// <remarks/> public byte RecordsReturned { get { return this.recordsReturnedField; } set { this.recordsReturnedField = value; } } /// <remarks/> public byte StartingRecord { get { return this.startingRecordField; } set { this.startingRecordField = value; } } /// <remarks/> public byte TotalRecords { get { return this.totalRecordsField; } set { this.totalRecordsField = value; } }}/// <remarks/>[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]public partial class SCResponseLink{ private string hrefField; private string relField; private string titleField; /// <remarks/> [System.Xml.Serialization.XmlAttributeAttribute()] public string href { get { return this.hrefField; } set { this.hrefField = value; } } /// <remarks/> [System.Xml.Serialization.XmlAttributeAttribute()] public string rel { get { return this.relField; } set { this.relField = value; } } /// <remarks/> [System.Xml.Serialization.XmlAttributeAttribute()] public string title { get { return this.titleField; } set { this.titleField = value; } }}/// <remarks/>[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]public partial class SCResponseNotifications{ private SCResponseNotificationsNotification notificationField; /// <remarks/> public SCResponseNotificationsNotification Notification { get { return this.notificationField; } set { this.notificationField = value; } }}/// <remarks/>[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]public partial class SCResponseNotificationsNotification{ private System.DateTime notificationDateField; private string notificationDetailsField; private string statusField; private string notificationTitleField; private string hrefField; /// <remarks/> public System.DateTime NotificationDate { get { return this.notificationDateField; } set { this.notificationDateField = value; } } /// <remarks/> public string NotificationDetails { get { return this.notificationDetailsField; } set { this.notificationDetailsField = value; } } /// <remarks/> public string Status { get { return this.statusField; } set { this.statusField = value; } } /// <remarks/> public string NotificationTitle { get { return this.notificationTitleField; } set { this.notificationTitleField = value; } } /// <remarks/> [System.Xml.Serialization.XmlAttributeAttribute()] public string href { get { return this.hrefField; } set { this.hrefField = value; } }}}\[/code\]The problem is, none of the object's fields get marshalled. Fields are null or zero after the call even though the XML returned from WebApi definitely has values. What could be going wrong? thanks.
 
Back
Top