我在尝试在C#Class中创建soap消息时遇到错误。
预订班级
public class GuestDetails
{
public string GuestTitle { get; set; }
public string GuestName { get; set; }
public string Address1 { get; set; }
public string Address2 { get; set; }
public string Address3 { get; set; }
public string Pincode { get; set; }
public string Country { get; set; }
public string Nationality { get; set; }
public string EmailId { get; set; }
public string PhoneNo { get; set; }
}
public class BookingDetails
{
public string BookingNumber { get; set; }
public string BookingDate { get; set; }
public string Bookedby { get; set; }
public string OTAId { get; set; }
public string OTAName { get; set; }
public string BookingStatus { get; set; }
public string CheckinDate { get; set; }
public string CheckinTime { get; set; }
public string CheckoutDate { get; set; }
public string CheckoutTime { get; set; }
}
public class RoomingDetail
{
public string RoomTypeId { get; set; }
public string RateId { get; set; }
public string NoOfRooms { get; set; }
public string Adult { get; set; }
public string Children { get; set; }
public string NoOfExtrabed { get; set; }
public string MealPlan { get; set; }
}
public class Hotel
{
public string hotelid { get; set; }
public GuestDetails GuestDetails { get; set; }
public BookingDetails BookingDetails { get; set; }
public List<RoomingDetail> RoomingDetails { get; set; }
}
[Serializable]
public class RootObject
{
public string accessKey { get; set; }
public string channelId { get; set; }
public List<Hotel> hotels { get; set; }
}
将C#类转换为Soap -
RootObject R = new RootObject();
R.accessKey = "";
R.channelId = "";
R.hotels = new List<Hotel>();
Hotel _hotel = new Hotel();
_hotel.hotelid = "3";
_hotel.GuestDetails = new GuestDetails();
_hotel.GuestDetails.GuestName = "GuestName";
_hotel.GuestDetails.GuestTitle = "GuestTitle";
_hotel.GuestDetails.Nationality = "Nationality";
_hotel.GuestDetails.PhoneNo = "PhoneNo";
_hotel.GuestDetails.Pincode = "Pincode";
_hotel.GuestDetails.Address1 = "Address1";
_hotel.GuestDetails.Address2 = "Address2";
_hotel.GuestDetails.Address3 = "Address3";
_hotel.GuestDetails.Country = "Country";
_hotel.GuestDetails.EmailId = "EmailId";
_hotel.RoomingDetails = new List<RoomingDetail>();
RoomingDetail _roomingDetails = new RoomingDetail();
_roomingDetails.Adult = "1";
_roomingDetails.Children = "2";
_roomingDetails.MealPlan = "sds";
_roomingDetails.NoOfExtrabed = "";
_roomingDetails.NoOfRooms = "1";
_roomingDetails.RateId = "222";
_roomingDetails.RoomTypeId = "11";
_hotel.RoomingDetails.Add(_roomingDetails);
_hotel.BookingDetails = new BookingDetails();
//BookingDetails _bookingDetails = new BookingDetails();
_hotel.BookingDetails.Bookedby = "Jagadees";
_hotel.BookingDetails.BookingDate = "05-08-2014";
_hotel.BookingDetails.BookingNumber = "15999";
_hotel.BookingDetails.BookingStatus = "Success";
_hotel.BookingDetails.CheckinDate = "03-09-2014";
_hotel.BookingDetails.CheckinTime = "";
_hotel.BookingDetails.CheckoutDate = "05-09-2014";
_hotel.BookingDetails.CheckoutTime = "";
_hotel.BookingDetails.OTAId = "";
_hotel.BookingDetails.OTAName = "";
R.hotels.Add(_hotel);
var r = new Random();
SoapFormatter formatter = new SoapFormatter();
string myTempFile = Path.Combine(Path.GetTempPath(), r.Next() + "SaveFile.txt");
GC.SuppressFinalize(myTempFile);
Stream objfilestream = new FileStream(myTempFile, FileMode.Create, FileAccess.Write, FileShare.None);
formatter.Serialize(objfilestream, R); <-- ERROR HERE -->
objfilestream.Close();
错误 -
SerializationException未被用户代码取消 Soap Serializer不支持序列化通用类型: System.Collections.Generic.List`1 [SoapwbApp.Hotel]。