0
C# 클래스로 마샬링하는 데 문제가있는 REST 서비스에서 일부 XML이 다시 나타납니다.WebAPI XML 응답을 C# 객체에 마샬링 할 수 없습니다.
XML은 다음과 같습니다
<?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>
자동 '으로 붙여 넣기'에 의해 생성 된 클래스는 다음과 같습니다 문제는
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;
}
}
}
}
입니다
, 객체의 필드 없음 마샬링되다. WebApi에서 반환 된 XML에 확실히 값이 있더라도 호출 후에는 필드가 null 또는 0입니다.무엇이 잘못 될 수 있습니까?
감사합니다.
감사합니다. 이것은 Global.asax.cs에 있어야합니까? 컴파일되지 않습니다. .NET 개발은 상당히 새로운 것입니다. – user486480
시리얼 화를위한 마이너 타입이 있습니다. 웹 호스팅을 사용하는 경우 구성은 정적 GlobalConfiguration.Configuration입니다. –
방금 오타가 오타를 만들었습니다 ... –