Asp.net web服务返回空对象

本文关键字:对象 返回 服务 net web Asp | 更新日期: 2023-09-27 18:13:35

我有一个XSD文件,它决定了我的引擎可以与其他插件(用不同的语言编写,如Delphi)通信的模式。我使用。net提供的XSD工具从XSD文件中获得一个c#类。

插件返回一个XML字符串,然后我将其反序列化为XSD工具生成的类。

在此之前一切都很好,但是当我通过web服务将类的数组传递给客户端时,该数组包含一个元素,这很好,但该对象中的每个字段要么为空,要么设置为默认值。

你知道为什么会这样吗?

我也尝试发送虚拟数据,而不是从插件正常检索数据,但仍然返回的对象是空的。

这是由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;
}

,只是为了测试的目的,我所做的是:

return return new BookingQueryResponse[1] { new BookingQueryResponse() { ArrivalDate = DateTime.Now.Date, DestinationName = "Malta" } };

Asp.net web服务返回空对象

请张贴XSD。由于您的类看起来很好,我最初的猜测是XSD和c#名称空间之间的类型(名称空间)不匹配。