0
我有一個XSD文件,它決定了我的引擎可以與其他插件(使用不同語言編寫,如Delphi)通信的模式。我使用.Net提供的XSD工具從XSD文件中獲取C#類。asp.net web服務返回空對象
插件返回一個XML字符串,然後我將其反序列化到由XSD工具生成的類中。
一切都很好,直到那裏,但是當我通過Web服務傳遞到客戶端的類的數組時,該數組包含一個元素,這是很好,但該對象中的每個字段爲null或設置爲其默認值。
任何想法爲什麼會發生這種情況?
我也嘗試發送虛擬數據,而不是通常從插件檢索數據,但仍然返回的對象是空的。
這是由XSD工具生成的類:
using System.Xml.Serialization;
/// <remarks/>
[System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
public class BookingQueryResponse {
/// <remarks/>
public int ErrorCode;
/// <remarks/>
public string ErrorString;
/// <remarks/>
public int BookingQueryID;
/// <remarks/>
public int DestinationID;
/// <remarks/>
public string DestinationName;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(DataType="date")]
public System.DateTime ArrivalDate;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(DataType="date")]
public System.DateTime DepartureDate;
/// <remarks/>
public int CurrencyID;
/// <remarks/>
public string CurrencyISO;
/// <remarks/>
public string CurrencySymbol;
/// <remarks/>
public int LangID;
/// <remarks/>
public string LangCode;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("HotelQuotePackages")]
public HotelQuotePackage[] HotelQuotePackages;
}
/// <remarks/>
public class HotelQuotePackage {
/// <remarks/>
public string PackageGuid;
/// <remarks/>
public string PackageName;
/// <remarks/>
public string PluginGuid;
/// <remarks/>
public int ResortID;
/// <remarks/>
public string ResortName;
/// <remarks/>
public int HotelID;
/// <remarks/>
public string HotelName;
/// <remarks/>
public int HotelRatingID;
/// <remarks/>
public string HotelRatingName;
/// <remarks/>
public string HotelNarrative;
/// <remarks/>
public System.Double MapLongitude;
/// <remarks/>
public System.Double MapLatitude;
/// <remarks/>
public string HotelRemark;
/// <remarks/>
public string OfferText;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("HotelRoomQuotes")]
public HotelRoomQuote[] HotelRoomQuotes;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("HotelImages")]
public HotelMediaImage[] HotelImages;
}
/// <remarks/>
public class HotelRoomQuote {
/// <remarks/>
public int RoomNumber;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("RoomQuotes")]
public RoomQuote[] RoomQuotes;
}
/// <remarks/>
public class RoomQuote {
/// <remarks/>
public string Guid;
/// <remarks/>
public int AdultPax;
/// <remarks/>
public int ChildPax;
/// <remarks/>
public int InfantPax;
/// <remarks/>
public string RoomTypeName;
/// <remarks/>
public string RoomTypeDesc;
/// <remarks/>
public int BoardBasisID;
/// <remarks/>
public string BoardBasisName;
/// <remarks/>
public System.Double CostForStay;
/// <remarks/>
public string Remarks;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("DayRates")]
public DayRate[] DayRates;
}
/// <remarks/>
public class DayRate {
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(DataType="date")]
public System.DateTime Date;
/// <remarks/>
public System.Double Rate;
}
/// <remarks/>
public class HotelMediaImage {
/// <remarks/>
public string HotelImage;
/// <remarks/>
public int ImageTypeID;
/// <remarks/>
public string ImageType;
}
,只是爲了測試Web服務,我所做的是這樣的:
return return new BookingQueryResponse[1] { new BookingQueryResponse() { ArrivalDate = DateTime.Now.Date, DestinationName = "Malta" } };
它聽起來像在xml中的不匹配和類型......很難說沒有具體細節雖然(即C#和XML) –
看看你的對象名稱空間(而不是c#命名空間,但xml名稱空間指定的屬性XmlType )在你生成的類和你的xml文件中,它們必須匹配! –
@Marc Gravell我編輯了這個問題,包括生成的c#類,如果它有幫助。 – Jonny