MVC または Web フォーム プロジェクトではなく、C# ASMX Web サービスに次のクラスがあります。
public class Hotel
{
public int HotelId {get;set;}
public string Name {get;set;}
public Room[] Room { get; set; }
[Range(0, 12, ErrorMessage = "Rating must be between 1 and 5")]
public int Rating {get;set:}
}
public class Room
{
[Required]
public int RoomId {get;set;}
[Required]
[StringLength(175)]
public string Name {get; set;}
}
上記のように有効にできるように、System.ComponentModel.DataAnnotationsを使用しますか? その場合、検証エラーの応答を取得するにはどうすればよいですか?
また、サービスの開始時に、以下のような Json データ オブジェクトを読み込みます。
oHotelRequest = JsonConvert.DeserializeObject<Hotel>(sJson);
HotelResponse oHotelResponse = BookingAPI.Hotel.Get(oHotelRequest);
return JsonConvert.SerializeObject(oHotelResponse);
または、オブジェクトを逆シリアル化するときに検証を実行できますか?